具有非透明UIBarButtonItem的透明UIToolBar

时间:2014-03-31 02:23:24

标签: ios7 uibarbuttonitem uitoolbar

我有一个透明的UIToolbar,通过设置半透明真实并更改背景alpha。如何让工具栏按钮不透明?我尝试添加这样的非透明图像:

CGRect rect = CGRectMake(0, 0, ([AppDelegate isInIPad])?768:320, 20);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColor redColor] CGColor]);
CGContextFillRect(context, rect);

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[self.filterButton setBackgroundImage:image forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];

1 个答案:

答案 0 :(得分:0)

试试这个:

[yourToolbar setBackgroundImage:[UIImage new] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];    
[yourToolbar setBackgroundColor:[UIColor clearColor]];    
[yourToolbar setShadowImage:[UIImage new] forToolbarPosition:UIToolbarPositionAny];