UIView(视图)

lazy var bgView: UIView = {
        
        let view = UIView ()
        view.backgroundColor = UIColor.white
        
        return view
    }()

       bgView.snp.makeConstraints { (make) -> Void in
        make.width.equalTo(50)
        make.height.equalTo(50)
        make.center.equalTo(self.view)
       }

线

lazy var viewLine: UIView = {
        
        let view = UIView ()
        view.backgroundColor = UIColor.gray
        
        return view
    }()
        self.contentView.addSubview(viewLine)

       viewLine.snp.makeConstraints { (make) -> Void in
        make.left.equalTo(self.contentView);
        make.right.equalTo(self.contentView);
        make.bottom.equalTo(self.descLable.top);
        make.height.equalTo(1);
       }

圆角+阴影


btnWeiXin.setShaowAndConner(sColor: UIColor.init(red: 204, green: 214, blue: 215)! ,offset: .init(width: 0, height: 1), radius: btnWeiXin.sc_height/2, sRadius: 4)

任意圆角

//保证已经形成frame 的情况下 
if let view = viewCenter {
           self.setCorner(cornerRadius: kViewRadius, corner: [.topLeft,.topRight])
}
// cell 里面用约束的布局情况下  self 在这能获取准确大小,self 的子视图则不行
override func layoutSubviews() {
        super.layoutSubviews()
        
        self.setCorner(cornerRadius: kViewRadius, corner: [.topLeft,.topRight])

    }
// cell  子视图 用约束的布局情况下 layoutIfNeeded 重要,
- (void)layoutSubviews{
    [super layoutSubviews];
    
    //获得准确frame,有时不管用 ,或     [self.viewCenter.superview layoutIfNeeded];
    override func layoutSubviews() {
        super.layoutSubviews()

        self.viewCenter.layoutIfNeeded()
        if let view = viewCenter {
            view.setCorner(cornerRadius: kViewRadius, corner: [.topLeft,.topRight])
        }


    }


}

渐变

    override func layoutSubviews() {
        super.layoutSubviews()

        viewCenter.layoutIfNeeded()
        viewCenter.setGradientLayer(colors: [UIColor.rgb(8,208,235).cgColor,UIColor.rgb(77,138,221).cgColor], startPoint: CGPoint(x: 0, y: 0), endPoint: CGPoint(x: 0, y: 1))
    }

你可能感兴趣的:(UIView(视图))