如何更改 UINavigation leftBarButtonItem 的颜色

发布于 2024-10-31 17:24:04 字数 638 浏览 3 评论 0原文

我希望我的 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]; 

I want my leftBarButtonItem to be a red button. I haven't figured out how to do that. I'm using the following code to construct the navigation bar and button.
Any help is appreciated.
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]; 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

圈圈圆圆圈圈 2024-11-07 17:24:04

也许您会在 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;

Maybe you will find a nicer solution in this posting at Stack Overflow or you can go the way using a 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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文