透明UIToolBar与不透明的UIBarButtonItem
问题描述:
我有一个透明的UIToolbar通过设置半透明真实和改变背景alpha。我怎样才能使工具栏按钮不透明?我尝试添加非透明的形象是这样的:透明UIToolBar与不透明的UIBarButtonItem
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];
答
试试这个:
[yourToolbar setBackgroundImage:[UIImage new] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
[yourToolbar setBackgroundColor:[UIColor clearColor]];
[yourToolbar setShadowImage:[UIImage new] forToolbarPosition:UIToolbarPositionAny];
希望有所帮助。 –