简体   繁体   English

在Swift中更改按钮的字体

[英]Changing the font of a button in Swift

I know this question has been asked before, and the question seemed to be solved, but I have an issue that I can't seem to solve. 我知道之前已经问过这个问题,问题似乎已经解决了,但我有一个我似乎无法解决的问题。 I'm trying to change to font of a UIButton using 我正在尝试使用更改为UIButton的字体

advanceButton.titleLabel!.font = UIFont (name: "ArchitectsDaughter", size: 17)

However, when I use this I get a compile message that 但是,当我使用它时,我收到一条编译消息

(AnyObject) ->() Does not have a member named 'titleLabel'

I've tried both the implicit, normal, and optional types for titleLabel but nothing will fix this. 我已经尝试了titleLabel的隐式,普通和可选类型,但没有什么能解决这个问题。 Can someone help me please? 有人能帮助我吗? Thanks in advance! 提前致谢!

Your advanceButton is not of type UIButton. 您的advanceButton不属于UIButton类型。

When you define advanceButton make sure it is of type UIButton. 定义advanceButton时,请确保它是UIButton类型。

like so, 像这样,

var advanceButton : UIButton = UIButton()
advanceButton.titleLabel!.font = UIFont(name: "Times New Roman", size: 25)

这看起来像你要么有一个名为方法advanceButton即与命名变量碰撞advanceButton或代替定义@IBOutlet为您的按钮,你定义的@IBAction

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM