我希望我的leftBarButtonItem是一个红色按钮。我还没弄明白怎么做。我正在使用以下代码来构建导航栏和按钮。 任何帮助表示赞赏。 LQ
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 :(得分: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;