【发布时间】:2012-02-03 18:16:01
【问题描述】:
我的 UIView 上有一个带有图层的框架。我让图层设置了背景颜色并设置了 alpha 0.5 并设置了 frame.backgroundColor = clearColor 以便人们可以看到它后面的线条。然而,它使包含文本的子视图也淡出。如何防止这种情况发生?
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setAlpha:kAlpha];
CALayer *layer = [self layer];
[layer setMasksToBounds:YES];
[layer setBackgroundColor:[UIColor redColor].CGColor];
[layer setCornerRadius:kCornerRadius];
}
return self;
}
- (id)init
{
if (self = [super init]) {
self.clipsToBounds = YES;
self.userInteractionEnabled = YES;
self.multipleTouchEnabled = NO;
tileTitle = [[UILabel alloc] init];
tileTitle.textColor = [UIColor blackColor];
tileTitle.backgroundColor = [UIColor clearColor];
tileTitle.font = [UIFont boldSystemFontOfSize:13.0f];
tileDescription = [[UILabel alloc] init];
tileDescription.textColor = [UIColor blackColor];
tileDescription.backgroundColor = [UIColor clearColor];
tileDescription.font = [UIFont systemFontOfSize:11.0f];
tileDescription.lineBreakMode = UILineBreakModeTailTruncation;
[self addSubview:tileTitle];
[self addSubview:tileDescription];
}
return self;
}
【问题讨论】:
标签: iphone objective-c uiview ios5