在Interface Builder中设置后,如何以编程方式修改UIBarButtonItem视图?
|
我已经在Interface Builder中创建了一个UIBarButton项,并将其链接到该类中的UIBarButton项属性。在Interface Builder中,其Style = Plain和Identifier = Custom,并且Title为空白。
在viewDidLoad方法的类文件中,我试图向此UIBarButtonItem属性添加自定义视图。
例如
UISegmentedControl *newButton = [[UISegmentedControl alloc] initWithItems:....];
newButton.momentary = YES;
newButton.segmentedControlStyle = UISegmentedControlStyleBar;
newButton.tintColor = [UIColor .....];
[self.myBarButtonItem setCustomView:newButton];
结果导致什么都没有显示。这是为什么?
我已经读过,如果我以编程方式创建UIBarButtonItem:
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:newButton];
然后将此BarButtonItem添加到工具栏-它将起作用。我的问题是我的工具栏上有很多东西,这个UIBarButton项必须在工具栏的FAR右边,如果我不能在界面生成器中直接链接到它,那么我就必须进行构建我所有的工具栏项目都以编程方式获得我需要的布局。
那么,当链接到IB中创建的UIBarButtonItem时,有没有办法使用customView做到这一点?
谢谢!
没有找到相关结果
已邀请:
1 个回复
枫湃揩乾纲