【发布时间】:2020-03-11 02:47:55
【问题描述】:
我正在尝试使用 setTitleColor 和 titleLabel! 创建 UIButton 并在其中显示文本,以及指定字体大小,但它不会显示在我的 Storyboard 中。如果我将这两行注释掉并取消注释 forgot.setTitle (当前已注释掉),它将起作用,但是我无法设置 UIButton 文本字体大小。有什么建议?我已在 viewdidload 中将子视图添加到我的视图中。
let forgotPassword: UIButton = {
let forgot = UIButton()
forgot.translatesAutoresizingMaskIntoConstraints = false
//forgot.setTitle("Forgot your password?", for: .normal)
forgot.titleLabel! .font = UIFont(name:"Forgot your password?", size: 14)
forgot.setTitleColor(.white, for: .normal)
forgot.addTarget(self, action: #selector(forgot(_ :)), for: .touchUpInside)
forgot.sizeToFit()
//forgot.backgroundColor = .orange
return forgot
}()
【问题讨论】:
标签: swift text colors uibutton