简体   繁体   English

iPhone SDK中的如何更改BarButton项目的颜色

[英]in iPhone SDK How to change the color of BarButton Item

How to change color of leftBarButtonItem of UIBarButtonItem in NavigationBar? 如何在NavigationBar中更改UIBarButtonItem的leftBarButtonItem的颜色?

if I am trying to set image in bar button through interfaceBuilder it shows border on image in bar button so is there any specific size for image for bar button or how to set image with-out showing border in it ? 如果我试图通过interfaceBuilder设置条形按钮中的图像,它会在条形按钮中的图像上显示边框,那么条形按钮的图像是否有特定的尺寸,或者如何设置不带边框的图像?

If I am adding BarButton dynamically it doesn"t appear while running App and if I am adding leftbarButton in xib only and connecting outlets then the leftbar button become visible but I am not able to assign customview view to it my ultimate goal is to change the color of left bar buttton 如果我动态添加BarButton,则在运行App时不会出现,并且如果我仅在xib中添加leftbarButton并连接插座,则leftbar按钮将变为可见,但我无法为其分配customview视图,我的最终目标是更改左杠but的颜色

Please Help and Suggest, Thanks 请帮助和建议,谢谢

Create the bar buttom item with a custom view using -[UIBarButtonItem initWithCustomView:] . 使用-[UIBarButtonItem initWithCustomView:]使用自定义视图创建条形项。 That way, you have all the control you want over the appearance. 这样,您就可以控制外观。

I think you can use: 我认为您可以使用:

- (id)initWithImage:(UIImage *)image style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action

You can set custom image for your bar button. 您可以为条形按钮设置自定义图像。

If it's just the colour you want to change, add the button to the bar and then set the tint colour of the bar (see docs on UINavigationBar or UIToolBar). 如果只是您要更改的颜色,则将按钮添加到条形,然后设置条形的颜色(请参阅UINavigationBar或UIToolBar上的文档)。 This of course changes the bar colour as well as the button however, but it's good practice (UI consistency wise) to use the same colour for UIBarButtonItems and their bars especially if you're using out-of-the-box buttons. 当然,这会同时更改条形和按钮的颜色,但是最好将UIBarButtonItems及其条形使用相同的颜色(特别是在使用开箱即用的按钮时)(在UI一致性方面)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM