简体   繁体   English

在导航栏中自定义UIBarButtonItem。

[英]Customising UIBarButtonItem in navigation bar.

I have a separate customisation class that does all the customisation of controls. 我有一个单独的自定义类,可以进行控件的所有自定义。 I am also customising navigation bar buttons. 我也在自定义导航栏按钮。

Now in navigation VC's viewDidLoad, I am passing a reference to the VC's leftBarButtonItem, to the customisation class, and the reference is of type UIBarButtonItem. 现在,在导航VC的viewDidLoad中,我将对VC的leftBarButtonItem的引用传递给自定义类,并且该引用的类型为UIBarButtonItem。 But how will he customisation class know, that the passed reference to the UIBarButtonItem is the left button? 但是,他的定制类将如何知道,传递给UIBarButtonItem的引用是向左按钮? I need the class to know this, since the customisation for left button is different from the right button. 我需要让类知道这一点,因为左按钮的自定义与右按钮不同。 I want to avoid creating a custom Enum for that, if it's possible to do it with built-in framework capabilities. 我想避免为此创建自定义枚举,如果可以使用内置框架功能实现的话。

Can you help please? 你能帮忙吗?

I did something similar a while back. 前一段时间我做了类似的事情。 You will probably want to make your customization method have an argument that tells it what kind of button you are passing 您可能希望使自定义方法具有一个参数,该参数告诉您要传递的按钮类型

[CustomizationClass customizeButton:leftBarButton ofType:kLeftBarButton];

Then make the customizeButton method check for the "ofType" and customize accordingly. 然后,使customizeButton方法检查“ ofType”并进行相应的自定义。

EDIT: just read what you said about custom enums. 编辑:只需阅读您关于自定义枚举的内容即可。 As far as I know, there is no way to detect this. 据我所知,没有办法检测到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM