【问题标题】:swift Button display快捷按钮显示
【发布时间】: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")")
}

}

【问题讨论】:

    标签: swift button uibutton


    【解决方案1】:

    您可以添加:

    testButton.setTitleColor(UIColor.redColor(), forState: .Highlighted)
    

    或者在按钮的功能中应用颜色:

    @IBAction func testButton(sender: UIButton) { 
        testButton.titleLabel.textColor = UIColor.redColor()
    }
    

    我在这里使用 redColor 作为示例,但您可以将其更改为您想要创建所需效果的任何颜色。我实际上并没有编译这个,所以如果您需要更正任何语法以使其正常工作,我们深表歉意。

    【讨论】:

      猜你喜欢
      • 2016-03-20
      • 1970-01-01
      • 2018-01-09
      • 2011-01-03
      • 2011-12-12
      • 2015-02-14
      • 1970-01-01
      • 1970-01-01
      • 2018-07-30
      相关资源
      最近更新 更多