如何使UIToolbar具有清晰的背景?
我有一个UIToolbar有一个白色的色调,一个酒吧button项目,其次是一些灵活的空间,其次是另一个酒吧button项目。 我想使工具栏完全清晰,以便我可以看到灵活空间下的内容(我不关心button后面的内容)。 有没有办法做到这一点? 我曾尝试将工具栏设置为半透明,但这并不能完全清楚。
任何帮助将不胜感激。
谢谢
[self.toolbar setBackgroundImage:[UIImage new] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault]; [self.toolbar setBackgroundColor:[UIColor clearColor]];
子类UIToolbar,并实现以下方法:
- (void)drawRect:(CGRect)rect { [[UIColor colorWithWhite:0 alpha:0.6f] set]; // or clearColor etc CGContextFillRect(UIGraphicsGetCurrentContext(), rect); }
在这里看到更多细节
像这样设置toolbarStyle -1
tools.barStyle = -1; // clear background
Hacky,对不起,但我迄今为止发现的唯一可以在iOS 7和iOS 6中正常工作的方法是:
[[toolbar.subviews objectAtIndex:0] removeFromSuperview];
如果您想要全球解决scheme利用UIAppearance
代理:
UIToolbar *toolbarAppearance = [UIToolbar appearance]; [toolbarAppearance setBackgroundImage:[[UIImage alloc] init] forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
无需在iOS 6+中进行子类化,就可以将属性translucent
设置为YES。
这在下面的iOS 5中不起作用。 没有子类化工具栏,可以这样做:
const float colorMask[6] = {222, 255, 222, 255, 222, 255}; UIImage *img = [[UIImage alloc] init]; UIImage *maskedImage = [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(img.CGImage, colorMask)]; [self.toolbar setBackgroundImage:maskedImage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
Swift 3版本接受的答案:
self.toolbar.isTranslucent = true self.toolbar.setBackgroundImage(UIImage(), forToolbarPosition: UIBarPosition.any, barMetrics: UIBarMetrics.default) self.toolbar.setShadowImage(UIImage(), forToolbarPosition: UIBarPosition.any)
- IOS应用程序 – 拦截来电并将其redirect到语音邮件
- iOS中的NSAttributedString中NSBackgroundColorAttributeName-like属性?
- 基于一个订购两个NSMutableArrays
- 如何在CALayer.contents中添加Stretchable UIImage?
- 如何传递属性swift 3 urlsession didFinishDownloadingTo后台下载后委托?
- 文件“Pods.xcconfig”无法打开,因为没有这样的文件
- Xcode iOS Xcode无线部署
- 如何添加一个定制的B2B应用程序的Apple ID?
- 计算远离另一对纬度/长度坐标特定距离的纬度/长度坐标