gpt4 book ai didi

ios - 选择器 View 快速出错

转载 作者:行者123 更新时间:2023-11-30 12:59:43 24 4
gpt4 key购买 nike

我正在尝试更改选择器 View 的文本字体和颜色。但是当我这样做时出现错误,请帮忙。

func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let attributedString = NSAttributedString(string: "some string", attributes: [NSForegroundColorAttributeName : UIColor.red])
return attributedString
}

ErrorImage

最佳答案

我通过提供这样的 View 做了类似的事情

    func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let pickerLabel = UILabel()
pickerLabel.textColor = UIColor.black
pickerLabel.text = "\(dataSource[row])"

pickerLabel.font = UIFont(name: "OpenSans-Light", size: 70)
pickerLabel.textAlignment = NSTextAlignment.center
return pickerLabel
}

func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return dataSource.count
}

关于ios - 选择器 View 快速出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39988150/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com