通过@H_403_2@stroyboard的运行时属性@H_403_2@runtime attribute可以对@H_403_2@Button设置圆角或者边框。@H_403_2@
1.@H_403_2@很多人都知道通常设置一个Button@H_403_2@或者其他UIIView@H_403_2@子类的圆角使用@H_403_2@
self.button.layer.cornerRadius = 10
这会用到layer@H_403_2@的图层属性来实现的,UIView@H_403_2@本身只是用来监听时间,而真正的现实内容的是layer@H_403_2@图层,这当然也包含动画的实现,比如我们对一个view@H_403_2@做的动画@H_403_2@
实际上也是对layer@H_403_2@做的动画@H_403_2@
2.@H_403_2@但是我们想知道如何通过xib @H_403_2@设置一个button@H_403_2@或者UIView@H_403_2@的圆角, @H_403_2@通过研究发现一种方法,这个方法就是runtime Attribute @H_403_2@运行时属性,也就是在运行时你设置这个属性才会起作用,这样体现了OC@H_403_2@语言的动态特性和运行时(runtime@H_403_2@)
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view,typically from a nib. } func test() { print([NSThread .isMainThread()] ) let i: BooleanType = true while i { print("***") } } override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) prepareUI() } func prepareUI() { self.view.addSubview(button) } lazy var button :UIButton = { let button = UIButton(type: UIButtonType.Custom) button.frame = CGRect(x: 50,y: 50,width: 100,height: 100) button.backgroundColor = UIColor.orangeColor() button.layer.cornerRadius = 50; return button }() override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }