Use*_*ser 54 uibutton ios swift
我想做一个圆形的拇指和拇指按下按钮.
我应该使用ImageView还是Button作为超类?
我如何在Swift中执行此操作?
vac*_*ama 137
这是一个示例圆形按钮:
斯威夫特3:
override func viewDidLoad() {
super.viewDidLoad()
let button = UIButton(type: .custom)
button.frame = CGRect(x: 160, y: 100, width: 50, height: 50)
button.layer.cornerRadius = 0.5 * button.bounds.size.width
button.clipsToBounds = true
button.setImage(UIImage(named:"thumbsUp.png"), for: .normal)
button.addTarget(self, action: #selector(thumbsUpButtonPressed), for: .touchUpInside)
view.addSubview(button)
}
func thumbsUpButtonPressed() {
print("thumbs up button pressed")
}
Run Code Online (Sandbox Code Playgroud)
Swift 2.x:
override func viewDidLoad() {
super.viewDidLoad()
let button = UIButton(type: .Custom)
button.frame = CGRect(x: 160, y: 100, width: 50, height: 50)
button.layer.cornerRadius = 0.5 * button.bounds.size.width
button.clipsToBounds = true
button.setImage(UIImage(named:"thumbsUp.png"), forState: .Normal)
button.addTarget(self, action: #selector(thumbsUpButtonPressed), forControlEvents: .TouchUpInside)
view.addSubview(button)
}
func thumbsUpButtonPressed() {
print("thumbs up button pressed")
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
72235 次 |
最近记录: |