按钮工具类:
import UIKit
class MFConfirmButton: UIButton {
override init(frame: CGRect) {
super.init(frame: frame)
layer.cornerRadius = 4
clipsToBounds = true
setTitleColor(UIColor.white, for: .normal)
setTitleColor(UIColor.init(rgb: 0x555555), for: .highlighted)
backgroundColor = UIColor(red: 210/255, green: 93/255, blue: 84/255, alpha:0xFF)
self.frame = CGRect(x: 30, y: 10, width: MFVariables.kScreenWidth-60, height: 46)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension UIColor {
convenience init(red: Int, green: Int, blue: Int) {
assert(red >= 0 && red <= 255, "Invalid red component")
assert(green >= 0 && green <= 255, "Invalid green component")
assert(blue >= 0 && blue <= 255, "Invalid blue component")
self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: 1.0)
}
convenience init(rgb: Int) {
self.init(
red: (rgb >> 16) & 0xFF,
green: (rgb >> 8) & 0xFF,
blue: rgb & 0xFF
)
}
}
使用方法:
let doneBtn = MFConfirmButton.init(frame: CGRect(x: 30, y: 10, width: cell.frame.size.width-60, height: cell.frame.size.height-20))
doneBtn.setTitle("确 定", for: .normal)
网友评论