【发布时间】:2015-09-14 13:09:24
【问题描述】:
我正在学习 Swift,我有一个基本问题。我不想使用情节提要,我想用代码创建一个按钮。目前,我这样编码我的按钮:
let button1: UIButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
button1.setImage(UIImage(named: "myImage.png"), forState: UIControlState.Normal)
button1.addTarget(self, action: "myMethod", forControlEvents: UIControlEvents.TouchUpInside)
button1.frame = CGRectMake(0, 0, 25, 25) // then I add this button to a navigation control
这可行,但我正在寻找稍微不同的东西。即:我想创建一个类,我想至少传递图像名称、按钮必须调用的方法和框架。此外,我想随时在我的 ViewController 中实例化按钮。
我在这里找到了很多帖子,但没有一个帖子真的有用(有些代码不起作用)。
你能帮帮我吗?
【问题讨论】:
标签: ios swift class uibutton extend