我有從UINavigationController
繼承的視圖控制器。我想設置rightBarButtonItem
。 我做了以下。以編程方式UINavigationBarItem
UINavigationItem* navItem = self.navigationItem;
UIButton* btnOptionsView = [[UIButton alloc] init];
[btnOptionsView setImage:[UIImage imageNamed:@"options.png"]
forState:UIControlStateNormal];
[btnOptionsView sizeToFit];
UIBarButtonItem* btnOptions = [[UIBarButtonItem alloc] initWithCustomView:btnOptionsView];
navItem.rightBarButtonItem = btnOptions;
但按鈕是不可見的,在調試模式下我已經注意到,btnOptions.width
爲0,而且我不能設置標題navItem
,像這樣
[navItem setTitle:@"title"]
不會改變標題爲UINavigationItem
。
not the navitem – TompaLompa 2012-04-23 13:07:35