Make a clear(transluscent) UIBarButttonItem IOS 5

冷暖自知 提交于 2019-12-08 04:09:03

问题


I am trying to set the tint color for a UIBarButtonItem using the following code, but all I get is a black button. Is there a way to accomplish this without the need to use custom images?

[[UIBarButtonItem appearance] SetTintColor:[UIColor clearColor]]:

回答1:


create a custom UIBarButtonItem with a button

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImage forState:UIControlStateNormal];

//set the frame of the button to the size of the image (see note below)
button.frame = CGRectMake(0, 0, 24, 24);
button.backgroundColor=[UIColor clearColor];    
//create a UIBarButtonItem with the button as a custom view
UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];



回答2:


If your UIToobar or UINavigationBar is translucent, bar buttons automatically become translucent.

[[self.navigationController navigationBar] setTranslucent:YES];

AFAIK, You can't make a bar button alone translucent.



来源:https://stackoverflow.com/questions/9138490/make-a-cleartransluscent-uibarbutttonitem-ios-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!