【发布时间】:2021-07-15 17:25:21
【问题描述】:
我目前在我的应用程序中使用“EmptyDataSet_Swift”来处理空状态,但我不知道如何正确使用 buttonTitle 函数来更改按钮的颜色。这是对它的引用:
/// Asks the data source for the title to be used for the specified button state.
/// The dataset uses a fixed font style by default, if no attributes are set. If you want a different font style, return a attributed string.
func buttonTitle(forEmptyDataSet scrollView: UIScrollView, for state: UIControl.State) -> NSAttributedString?
我能够做的是更改文本的标题,但是当我更改前景色时,我收到一个错误。这是我的代码:
func buttonTitle(forEmptyDataSet scrollView: UIScrollView, for state: UIControl.State) -> NSAttributedString? {
let buttonTitle = "Add a Project"
let buttonTitleAttributes: [NSAttributedString.Key: Any] = [
.font: UIFont(name: "HelveticaNeue-Bold", size: 14),
.foregroundColor: UIColor.green.cgColor
]
let attributedButtonTitle = NSAttributedString(string: buttonTitle, attributes: buttonTitleAttributes)
return attributedButtonTitle
}
EmptyDataSet_Swift:https://github.com/Xiaoye220/EmptyDataSet-Swift
【问题讨论】:
标签: ios swift xcode button nsattributedstring