UIView(视图)

@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 获取子视图的真实坐标,获得准确frame 保证已经形成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关联的控制器中 保证已经形成frame 的情况下  (在控制器中--viewDidLayoutSubviews 下写)
[self.imvBg.superview layoutIfNeeded];
[self.imvBg mj_corner:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadius:8];


// cell  子视图 用约束的布局情况下 layoutIfNeeded 重要,
- (void)layoutSubviews{
    [super layoutSubviews];
    
    //获得准确frame,有时不管用 ,或     [self.viewCenter.superview layoutIfNeeded];
    [self.viewCenter.superview layoutIfNeeded];
    [self.viewCenter mj_corner: UIRectCornerTopLeft | UIRectCornerTopRight cornerRadius:cornerRadius];
    NSLog(@"--222--%@",NSStringFromCGRect(self.viewCenter.frame));


}

阴影
实现UIView任意圆角+绘制阴影
https://www.jianshu.com/p/c47c52e9a8e3

image.png

CAShapeLayer 画线

UIView 的 clipsTobounds 属性
https://www.jianshu.com/p/d50789913a65
圆角箭头矩形 提示框
https://www.jianshu.com/p/0c609bf5cb6f

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容