Swift 设置按钮圆角 代码&Xib

通过stroyboard的运行时属性runtime attribute可以对Button设置圆角或者边框。

1.很多人都知道通常设置一个Button或者其他UIIView子类的圆角使用

self.button.layer.cornerRadius = 10

这会用到layer的图层属性来实现的,UIView本身只是用来监听时间,而真正的现实内容的是layer图层,这当然也包含动画的实现,比如我们对一个view做的动画

实际上也是对layer做的动画

2.但是我们想知道如何通过xib 设置一个button或者UIView的圆角, 通过研究发现一种方法,这个方法就是runtime Attribute 运行时属性,也就是在运行时你设置这个属性才会起作用,这样体现了OC语言的动态特性和运行时(runtime





@H_502_68@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. } }

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...