@property (nonatomic, strong) UIView *viewBg;
- (UIView *)viewBg {
if (!_viewBg) {
UIView *view = [[UIView alloc] init];
view.backgroundColor = [UIColor grayColor];
_viewBg = view;
}
return _viewBg;
}
[self.viewBg mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view);
make.height.equalTo(@30);
make.width.equalTo(@30);
}];
線
@property (nonatomic, strong) UIView *viewLine;
- (UIView *)viewLine {
if (!_viewLine) {
UIView *view = [[UIView alloc] init];
view.backgroundColor = [UIColor grayColor];
_viewLine = view;
}
return _viewLine;
}
[self.view addSubview:self.viewLine];
[self.viewLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view);
make.right.equalTo(self.view);
make.height.equalTo(@(0.5));
}];
拓展
#圓角
[self.view mj_cornerRadius:5];
#邊框
[self.view mj_borderColor:UIColor.blackColor width:1];
#圓角+陰影
[self.bgView mj_dropShadowWithOffset:CGSizeMake(0, 3)
cornerRadius:8
radius:8
color:[UIColor colorWithHexString:@"#DDDDDD" alpha:0.51]
opacity:1];
#任意圓角+陰影
[self.bgView mj_corner:UIRectCornerTopLeft | UIRectCornerTopRight sColor:UIColor.redColor offset:CGSizeMake(0, 3) radius:8 sRadius:8 opacity:1 bgColor:UIColor.whiteColor];
漸變
- (void)layoutSubviews{
[super layoutSubviews];
//layoutifneed 獲取子視圖的真實坐標(biāo),獲得準(zhǔn)確frame 保證已經(jīng)形成frame 的情況下
[self.bgView.superview layoutIfNeeded];
[self.bgView mj_gradientLayerWithColors:@[(id)rgb(255,85,85).CGColor,(id)rgb(255,127,76).CGColor] startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
NSLog(@"===實際===size=====%@",NSStringFromCGRect(self.bgView.frame));
}
任意圓角
//在xib關(guān)聯(lián)的控制器中 保證已經(jīng)形成frame 的情況下 (在控制器中--viewDidLayoutSubviews 下寫)
[self.imvBg.superview layoutIfNeeded];
[self.imvBg mj_corner:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadius:8];
// cell 子視圖 用約束的布局情況下 layoutIfNeeded 重要,
- (void)layoutSubviews{
[super layoutSubviews];
//獲得準(zhǔn)確frame,有時不管用 扰她,或 [self.viewCenter.superview layoutIfNeeded];
[self.viewCenter.superview layoutIfNeeded];
[self.viewCenter mj_corner: UIRectCornerTopLeft | UIRectCornerTopRight cornerRadius:cornerRadius];
NSLog(@"--222--%@",NSStringFromCGRect(self.viewCenter.frame));
}
陰影
實現(xiàn)UIView任意圓角+繪制陰影
http://www.reibang.com/p/c47c52e9a8e3
image.png
UIView 的 clipsTobounds 屬性
http://www.reibang.com/p/d50789913a65
圓角箭頭矩形 提示框
http://www.reibang.com/p/0c609bf5cb6f