【发布时间】:2016-06-07 08:37:39
【问题描述】:
我从我的代码中创建了一个按钮。
如何编写代码让按钮更改为默认值?
我错过了一些代码吗?
我试过adjustsImageWhenHighlighted 什么的......
我的意思是当我按下按钮时..按钮将变得透明(我仍然按下)并且当我按下时会变回来......
就像下面两张图片...
import UIKit
class ViewController: UIViewController {
var testButton:UIButton = UIButton()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = UIColor.whiteColor()
testButton.frame = CGRect(x: 100, y: 100, width: 100, height: 100)
testButton.backgroundColor = UIColor.whiteColor()
testButton.setTitle("123", forState:.Normal)
testButton.setTitleColor(UIColor.blueColor(), forState: .Normal)
testButton.tag = 1
testButton.addTarget(self, action: #selector(number), forControlEvents: .TouchUpInside)
self.view.addSubview(testButton)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func number(){
print("\("100")")
}
}
【问题讨论】: