圆角按钮【例如:圆形头像】
let image = UIImage(named: "user_avatar")
self.button.setImage(image, forState: UIControlState.Normal)
self.button.imageView?.layer.cornerRadius = self.button.frame.width / 2
复选按钮
func checkBoxButton() {
let frame = CGRectMake(68, 79, 300, 128)
let button = UIButton(type: UIButtonType.Custom)
button.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
button.frame = frame
button.titleLabel?.font = UIFont.systemFontOfSize(30)
button.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Left
button.setTitle("复选框按钮", forState: UIControlState.Normal)
//上面是样式的设定,下面才是跟复选框有关
button.addTarget(self, action: "buttonPressed:", forControlEvents: UIControlEvents.TouchUpInside)
button.setImage(UIImage(named: "check"), forState: UIControlState.Normal)
button.setImage(UIImage(named: "uncheck"), forState: UIControlState.Selected)
self.view.addSubview(button)
}
func buttonPressed(button: UIButton) {
button.selected = !button.selected
}