美文网首页
设置透明度却不影响子视图

设置透明度却不影响子视图

作者: 骑着蜗牛的乌龟 | 来源:发表于2016-11-21 15:10 被阅读0次

// Returns a color in the same color space as the receiver with the specified alpha component.

- (UIColor *)colorWithAlphaComponent:(CGFloat)alpha;

//需要透明度的View

UIView *vagueView = [[UIView alloc] init];

[vagueView setBackgroundColor:

          [[UIColor whiteColor] colorWithAlphaComponent:0.5]];

[self addSubview:vagueView];

[vagueView mas_makeConstraints:^(MASConstraintMaker *make) {

make.top.mas_equalTo(self.mas_top).offset(50);

make.centerX.mas_equalTo(self.mas_centerX).offset(0);

make.size.mas_equalTo(CGSizeMake(65, 65));

}];

[vagueView.layer setMasksToBounds:YES];

[vagueView.layer setCornerRadius:32.5];

//如果直接设置alpha 会影响到的子视图

UIButton *headBtn = [UIButton buttonWithType:UIButtonTypeCustom];

[headBtn setImage:[ECIMAGENAME(@"user") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]  forState:UIControlStateNormal];

[headBtn addTarget:self action:@selector(headerAction:) forControlEvents:UIControlEventTouchUpInside];

[vagueView addSubview:headBtn];

self.headBtn = headBtn;

[headBtn mas_makeConstraints:^(MASConstraintMaker *make) {

make.top.mas_equalTo(vagueView.mas_top).offset(2.5);

make.centerX.mas_equalTo(vagueView.mas_centerX).offset(0);

make.size.mas_equalTo(CGSizeMake(60, 60));

}];

[_headBtn.layer setMasksToBounds:YES];

[_headBtn.layer setCornerRadius:30];

相关文章

网友评论

      本文标题:设置透明度却不影响子视图

      本文链接:https://www.haomeiwen.com/subject/omeupttx.html