2011-04-10 37 views
0

我希望我的leftBarButtonItem爲紅色按鈕。我還沒有想出如何做到這一點。我使用下面的代碼來構造導航欄和按鈕。 任何幫助表示讚賞。 LQ如何更改UINavigation的顏色leftBarButtonItem

UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; 
navBar.barStyle = UIBarStyleBlack; 
navBar.translucent = YES; 
[self.view addSubview:navBar]; 
[navBar release]; 

UIBarButtonItem *clearButton = [[UIBarButtonItem alloc] 
initWithTitle:@"Clear" 
style:UIBarButtonItemStyleBordered 
target:self 
action:@selector(myAction:)]; 

navItem.leftBarButtonItem = clearButton; 
[navBar pushNavigationItem:navItem animated:false]; 
[navBar setDelegate:self];  
[navItem release]; 
[clearButton release]; 

回答

0

也許你會發現在this posting at Stack Overflow一個更好的解決方案,也可以使用一個UISegmentedControl

UISegmentedControl *button = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Clear", nil]] autorelease]; 
button.momentary = YES; 
button.segmentedControlStyle = UISegmentedControlStyleBar; 
button.tintColor = [UIColor redColor]; 
... 
UIBarButtonItem *clearButton = [[UIBarButtonItem alloc] initWithCustomView:button]; 

navItem.leftBarButtonItem = clearButton; 
+0

感謝要走的路。我從來沒有想過使用UISegmentedControl。 – 2011-04-10 21:10:04