[英]UIButton and image
我将如何制作UIButton并为其分配图像,而无需输入文本,而不仅仅是连接IBAction? 我是新手,不能在游戏中使用情节提要。 我非常感谢您的帮助。 谢谢
我认为这样可以帮助您创建带有图像的UIButton并在单击时执行操作。
let aBtn = UIButton(type: UIButtonType.Custom) as UIButton
aBtn.frame = CGRectMake(x , y, width, height)
aBtn.setBackgroundImage(UIImage(named: "your image"), forState: .Normal)
aBtn.addTarget(self, action:"buttonClicked:", forControlEvents: UIControlEvents.TouchUpInside)
view.addSubview(aBtn)
单击按钮后,您可以执行某些功能。
func buttonClicked(sender: UIButton){
//your code here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.