Ios 如何使用swift在Xcode中创建自定义按钮?
我正在尝试使用swift在Xcode 6中创建自定义按钮,但我不确定如何继续。我是否应该使用助手编辑器在viewController.swift文件中创建一个类,然后将该类应用于相关按钮 这里有一个hello world的例子Ios 如何使用swift在Xcode中创建自定义按钮?,ios,swift,uibutton,xcode6,Ios,Swift,Uibutton,Xcode6,我正在尝试使用swift在Xcode 6中创建自定义按钮,但我不确定如何继续。我是否应该使用助手编辑器在viewController.swift文件中创建一个类,然后将该类应用于相关按钮 这里有一个hello world的例子 class myViewcontroller: UIViewController{ var helloLabel : UILabel! var abutton :UIButton! func viewTapped(sender : AnyObject) {
class myViewcontroller: UIViewController{
var helloLabel : UILabel!
var abutton :UIButton!
func viewTapped(sender : AnyObject) {
if (helloLabel.text == "tap it again please good sir"){
self.dismissViewControllerAnimated(true, completion: nil)
}
helloLabel.text = "tap it again please good sir"
}
override func awakeFromNib() {
super.awakeFromNib()
}
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.redColor()
helloLabel = UILabel(frame: CGRectMake(50, 50, 150, 50))
helloLabel.text = "hello world"
helloLabel.textColor = UIColor.whiteColor()
abutton = UIButton(frame: CGRectMake(50, 100, 100, 50))
abutton.backgroundColor = UIColor.greenColor()
abutton.setTitle("Test Button", forState: UIControlState.Normal)
abutton.addTarget(self, action: "viewTapped:", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(abutton)
self.view .addSubview(helloLabel)
// Do any additional setup after loading the view, typically from a nib.
}
}
您希望以编程方式还是在Interface Builder中进行设置?