And*_* M. 3 uibutton uilabel ios swift
我有以下代码
let width = UIScreen.mainScreen().bounds.width
let linkLabel = UILabel(frame: CGRect(x: 8, y: contentHeight, width: 100, height: labelHeight))
let linkButton = UIButton(frame: CGRect(x: 108, y: contentHeight, width: width - 108, height: labelHeight))
mainScrollView.addSubview(linkLabel)
mainScrollView.addSubview(linkButton)
linkLabel.text = "Link:"
linkButton.addTarget(self, action: #selector(linkButtonPressed), forControlEvents: .TouchUpInside)
linkButton.setTitle("http://example.com", forState: .Normal)
linkButton.layer.borderWidth = 1.0
mainScrollView.contentSize = CGSize(width: view.frame.width, height: contentHeight)
Run Code Online (Sandbox Code Playgroud)
所以标题不可见,但是当我点击按钮时,我可以获取它的标题属性
func linkButtonPressed(sender: UIButton) {
print("button title = \(sender.titleLabel?.text)")
}
Run Code Online (Sandbox Code Playgroud)
我得到了button title = Optional("http://example.com")但无论如何按钮标题不可见。有什么建议?
您的按钮标题显示但为白色。为按钮标题提供任何颜色。您的代码没有问题。
linkButton.setTitle("http://example.com", forState: .Normal)
linkButton.setTitleColor(UIColor.redColor(), forState: UIControlState.Normal)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2653 次 |
| 最近记录: |