DJButton
https://github.com/shileseal/DJButton
欢迎star和fork
一个自定义Button中imageView和titleLabel位置的自定义控件
功能
- 快速创建4种布局的UIButton (1.左icon,右title 2.左title,右icon 3.上icon,下title 4.上title, 下icon)
- 轻松设定icon和title之间的距离
- 实时渲染到Attributes Inspector,用Storyboard创建时,所见即所得
用法
// 1.样式:左标题右图片
let firstButton = DJButton(layoutStyle: .leftTitleImage)
firstButton.setTitle("button", for: .normal)
firstButton.setTitleColor(UIColor.red, for: .normal)
firstButton.setImage(UIImage(named: "icon"), for: .normal)
firstButton.frame = CGRect(x: 0, y: 0, width: 110, height: 110)
// 图片和标题之间的间隔
firstButton.gap = 20
self.view.addSubview(firstButton)
// 2.样式:上图片下标题
let secondButton = DJButton(layoutStyle: .upImageTitle)
secondButton.setTitle("button", for: .normal)
secondButton.setTitleColor(UIColor.red, for: .normal)
secondButton.setImage(UIImage(named: "icon"), for: .normal)
secondButton.frame = CGRect(x: 0, y: 150, width: 110, height: 110)
secondButton.gap = 10
self.view.addSubview(secondButton)
// 3.样式:上标题下图片
let thirdButton = DJButton(layoutStyle: .upTitleImage)
thirdButton.setTitle("button", for: .normal)
thirdButton.setTitleColor(UIColor.red, for: .normal)
thirdButton.setImage(UIImage(named: "icon"), for: .normal)
thirdButton.frame = CGRect(x: 0, y: 300, width: 110, height: 110)
thirdButton.gap = 20
self.view.addSubview(thirdButton)
// 4.样式:Storyboard创建,请参照Main.Storyboard
网友评论