5
我想要兩個rightBarButtonItem在我的UINavigationBar上。我怎樣才能做到這一點?如何將兩個UIBarButtonItems添加到UINavigationItem?
我想要兩個rightBarButtonItem在我的UINavigationBar上。我怎樣才能做到這一點?如何將兩個UIBarButtonItems添加到UINavigationItem?
您可以使用帶有兩個按鈕的UISegmentedControl,並將其配置爲momentary
屬性設置爲YES。
這是郵件應用程序用於轉到下一個/上一個消息的內容。
更新
爲了分配UISegmentedControl] 1爲右鍵,你必須把它包裝一個的UIBarButtonItem(從NavBar sample application採取的示例代碼)中:
- (void)viewDidLoad
{
// "Segmented" control to the right
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:
[UIImage imageNamed:@"up.png"],
[UIImage imageNamed:@"down.png"],
nil]];
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segmentedControl.frame = CGRectMake(0, 0, 90, kCustomButtonHeight);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.momentary = YES;
UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[segmentedControl release];
self.navigationItem.rightBarButtonItem = segmentBarItem;
[segmentBarItem release];
}
能一個UISegmentedControl作爲UIBarButtonItem被鑄造? – 2010-06-10 02:05:15
我已更新我的答案,以顯示如何使用UISegmentedControl作爲rightBarButtonItem。 – 2010-06-10 07:09:39