繁体   English   中英

iOS-[UIColor clearColor]和UIToolbars

[英]iOS - [UIColor clearColor] and UIToolbars

我一直在尝试将[UIColor clearColor]UIToolbar配合使用,以使自定义控件界面更适合“机械”应用程序(想想您在70年代的电影中会看到的按钮)。

发生的事情是,当我将工具栏设置为clearColor时,它正在将其变成无光泽的黑色。 它后面的图像是红色,棕褐色和黑色,因此我确定它无法正常工作。

我看到的一个区别是,我使用的是导航控制器上的工具栏,而不是独立的UIToolbar

代码行是

self.navigationController.toolbar.translucent = YES;
self.navigationController.toolbar.backgroundColor = [UIColor clearColor];

而我的上方导航栏(在另一个视图中设置)是UIBarStyleBlackTranslucent ,这可以扔掉它吗?

跟踪此问题的任何帮助都将非常有用。

您可以使用以下代码为导航控制器的工具栏设置透明背景:

// UIToolbar.h
@interface UIToolbar (Transparency)
- (void)drawRect:(CGRect)rect;
@end
// UIToolbar.m
#import "TransparentToolbar.h"
@implementation UIToolbar (Transparency)
- (void)drawRect:(CGRect)rect {
    [[UIColor clearColor] set];
    CGContextFillRect(UIGraphicsGetCurrentContext(), rect);
}
@end

用法:

// bar_bottom_bumped.png is a toolbar image with transparency
UIImage *bg = [UIImage imageNamed:@"bar_bottom_bumped.png"];
UIImageView *background = [[UIImageView alloc] initWithImage:bg];
background.frame = self.navigationController.toolbar.bounds;
background.autoresizingMask = UIViewAutoresizingFlexibleWidth;
BOOL isIOS5 = [[[UIDevice currentDevice] systemVersion] intValue] >= 5;
self.navigationController.toolbar.backgroundColor = [UIColor clearColor];
[self.navigationController.toolbar insertSubview:background atIndex: (isIOS5 ? 1 : 0)];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM