我在Interface Builder中創建了一個UIBarButton項目,並將它鏈接到類中的UIBarButton項目屬性。在Interface Builder中它是Style = Plain and Identifier = Custom and it's Title is blank。如何在Interface Builder中設置後以編程方式修改UIBarButtonItem視圖?
viewDidLoad方法中的類文件內我想將自定義視圖添加到此UIBarButtonItem屬性。
E.g
UISegmentedControl *newButton = [[UISegmentedControl alloc] initWithItems:....];
newButton.momentary = YES;
newButton.segmentedControlStyle = UISegmentedControlStyleBar;
newButton.tintColor = [UIColor .....];
[self.myBarButtonItem setCustomView:newButton];
,這導致NOTHING顯示出來的。這是爲什麼?
我讀過,如果我編程方式創建的UIBarButtonItem:
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:newButton];
然後這個BarButtonItem添加到工具欄 - 這是可行的。我的問題是我有很多東西在我的工具欄上,這個UIBarButton項目需要在工具欄的FAR右側,如果我不能直接在界面生成器中鏈接它,那麼我將不得不構建所有我的工具欄項目編程獲取我需要的佈局。
所以當鏈接到在IB中創建的UIBarButtonItem時,有沒有辦法用customView做到這一點?
謝謝!
我用我喜歡用的方法編輯我的答案,這樣我就不再是這樣一個便宜的混蛋了;) – 2011-04-13 21:46:17