我想使用下面的代码设置UIBarButtonItem的色调颜色,但我所得到的只是一个黑色按钮。有没有办法做到这一点,而不需要使用自定义图像?明确(半透明)的UIBarButttonItem IOS 5
[[UIBarButtonItem appearance] SetTintColor:[UIColor clearColor]]:
我想使用下面的代码设置UIBarButtonItem的色调颜色,但我所得到的只是一个黑色按钮。有没有办法做到这一点,而不需要使用自定义图像?明确(半透明)的UIBarButttonItem IOS 5
[[UIBarButtonItem appearance] SetTintColor:[UIColor clearColor]]:
创建自定义的UIBarButtonItem一个按钮
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];
如果您UIToobar或UINavigationBar的是半透明的,栏按钮自动变成半透明。
[[self.navigationController navigationBar] setTranslucent:YES];
据我所知,你不能让一个栏按钮单独半透明。
我这样做,它似乎UIBarButtonItems仍然通过黑色的到来。有任何想法吗? – zachzurn 2012-02-04 04:59:02
我可以做到这一点,主要问题是我有设计师通过故事板添加按钮。这样做意味着我将不得不以编程方式添加所有按钮。 – zachzurn 2012-02-04 05:11:04
您可以创建网点到您的customBarItem,然后可以设置customBarItem的属性,像这样customBarItem.customView = button; – 2012-02-04 05:26:12
用清晰的按钮图像完成此操作。 – zachzurn 2012-02-04 06:07:27