我一直在用不同類型的代碼爭取幾個小時來將自定義項添加到導航欄中。不幸的是它失敗了,沒有調試錯誤。現在我只能改變欄的標題。如何將自定義項添加到導航欄中
的代碼在viewDidLoad方法中添加了特殊的ViewController:
UIBarButtonItem *gotoNext = [[UIBarButtonItem alloc] initWithTitle:@"Goto next" style:UIBarButtonItemStylePlain target:self action:@selector(gotoNextAction)];
self.navigationItem.rightBarButtonItem = gotoNext;
我嘗試下面的代碼,但遺憾的是沒有任何的運氣:
UIView* container = [[UIView alloc] init];
UIButton * button = [[UIButton alloc] init];
[button setTitle:@"Test" forState:UIControlStateNormal];
[container addSubview:button];
UIBarButtonItem* item = [[UIBarButtonItem alloc] initWithCustomView:container];
self.navigationItem.rightBarButtonItem = item;
凡是設置容器的框架?背景顏色 ? – Mangesh