酱油06-layer

layer

layer-->CAlayer-->NSObject

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //layer是UI view的一个属性,layer-->CAlayer-->NSObject
        
        
        let but = UIButton(type: .System)
        but.frame = CGRect(x: 100, y: 100, width: 100, height: 100)
        but.backgroundColor = UIColor.redColor()
        self.view.addSubview(but)
        
        //设置圆角,当为其宽高的一半时就变为了圆形
        but.layer.cornerRadius = 50
        //设置边框的颜色
        but.layer.borderColor = UIColor.greenColor().CGColor
        //设置边框的宽度
        but.layer.borderWidth = 5
        
        //设置阴影的颜色
        but.layer.shadowColor = UIColor.brownColor().CGColor
        
        //设置阴影的大小
        but.layer.shadowRadius = 5
        //设置阴影的偏移量,对阴影进行移动,默认和原视图一样大小
        but.layer.shadowOffset = CGSize(width: 10, height: 10)
        
        //设置阴影可见,(默认为0,不可见)
        but.layer.shadowOpacity = 1
        
        
        let v = UIView(frame: CGRect(x: 100, y: 210, width: 100, height: 60))
        //设置视图变换(a/d为左右上下拉伸,b/c为沿矩形的长宽平分线,tx/ty为x/y轴偏移(右下为正))
        v.transform = CGAffineTransform(a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0)
        v.backgroundColor = UIColor.blueColor()
        self.view.addSubview(v)
    }
}

你可能感兴趣的:(酱油06-layer)