IOS Swift3.0 UiView Demo1

来源:互联网 发布:做假章软件 编辑:程序博客网 时间:2024/05/03 16:51
import UIKit


class ViewController: UIViewController {


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let viewRect = CGRect(x: 50, y: 50, width: 100, height: 100)
        let view1 = MyView(frame: viewRect)
        self.view.addSubview(view1)
    }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}


class MyView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        //把背景色设为透明
        self.backgroundColor = UIColor.clear
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func draw(_ rect: CGRect) {
        let pathRect = self.bounds.insetBy(dx: 1, dy: 1)
        let path = UIBezierPath(roundedRect: pathRect, cornerRadius: 10)
        path.lineWidth = 3
        
        UIColor.green.setFill()
        UIColor.blue.setStroke()
        
        path.fill()
        path.stroke()
    }
}
原创粉丝点击