8.21 Draw绘图 画圆

要注意,所有的图形都是矩形,圆形只是多了圆角

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let btn = UIButton(type: .System)
        btn.frame = CGRect(x: 100, y: 100, width: 100, height: 100)
        btn.backgroundColor = UIColor.redColor()
        self.view.addSubview(btn)
        
        btn.layer.cornerRadius = 50     //圆角半径
        btn.layer.borderColor = UIColor.yellowColor().CGColor //边框颜色
        btn.layer.borderWidth = 2    //边框宽度
        
        btn.layer.shadowColor = UIColor.blackColor().CGColor
        btn.layer.shadowOpacity = 1  //透明度,默认是0,透明的看不见,改成1
        btn.layer.shadowOffset = CGSize(width: -40, height: -20) //width,height为负数则往左往上
        btn.layer.shadowRadius = 20   // 阴影半径
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

编译运行,结果如下图:

8.21 Draw绘图 画圆_第1张图片
Paste_Image.png

你可能感兴趣的:(8.21 Draw绘图 画圆)