我希望您能为按钮设置一个属性字符串。
在 Swift 中,此函数的定义如下:
func setAttributedTitle(_ title: NSAttributedString!,
forState state: UIControlState)
所以我认为我需要像这样输入它
。myButton.setAttributedTitle(title:attrString, forState: UIControlState.Normal)
但正确的写法是
myButton.setAttributedTitle(attrString, forState: UIControlState.Normal)
为什么需要放置 forState:
而不是 title
?我不明白。
顺便问一下,函数定义中下划线的含义是什么?
var attrString = NSAttributedString("Hello World", attributes:dictAttributes)
不起作用,而var attrString = NSAttributedString(string: "Hello World", attributes:dictAttributes)
起作用呢? - DuckforState
。forState
是该函数的本地参数名和外部参数名。您可以在官方指南中找到有关此的大量信息。 - Gabriele Petronella