gpt4 book ai didi

cocoa - UIPickerView 不允许通过委托(delegate)的 `attributedTitleForRow...` 更改字体名称和大小

转载 作者:行者123 更新时间:2023-12-03 16:01:20 27 4
gpt4 key购买 nike

我使用以下函数来更改字体颜色和字体大小,颜色有效,但字体名称和字体大小不起作用。

func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? 

var myTitle = NSAttributedString(string: titleData, attributes: [NSFontAttributeName:UIFont(name: "Arial-BoldMT", size: 45)!, NSForegroundColorAttributeName:UIColor.whiteColor()])

有什么帮助吗?

谢谢。

最佳答案

我有另一个选择可能对你有帮助..

完成正常选择器 View 所需的所有工作:获取更多帮助 UIPickerView make in Swift iOS

现在按照此步骤操作: - 您可以使用 viewForRow 方法,如下所示

func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView!) -> UIView
{
var pickerLabel = UILabel()
pickerLabel.textColor = UIColor.blackColor()
pickerLabel.text = "PickerView Cell Title"
// pickerLabel.font = UIFont(name: pickerLabel.font.fontName, size: 15)
pickerLabel.font = UIFont(name: "Arial-BoldMT", size: 15) // In this use your custom font
pickerLabel.textAlignment = NSTextAlignment.Center
return pickerLabel
}

更新了 Swift 3

func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView!) -> UIView
{
let pickerLabel = UILabel()
pickerLabel.textColor = UIColor.black
pickerLabel.text = "PickerView Cell Title"
// pickerLabel.font = UIFont(name: pickerLabel.font.fontName, size: 15)
pickerLabel.font = UIFont(name: "Arial-BoldMT", size: 15) // In this use your custom font
pickerLabel.textAlignment = NSTextAlignment.center
return pickerLabel
}

更新了 Swift 5

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView
{
let pickerLabel = UILabel()
pickerLabel.textColor = UIColor.white
pickerLabel.text = "PickerView Cell Title"
// pickerLabel.font = UIFont(name: pickerLabel.font.fontName, size: 15)
pickerLabel.font = UIFont.boldSystemFont(ofSize: 20) // In this use your custom font
pickerLabel.textAlignment = NSTextAlignment.center
return pickerLabel
}

也许它对你有帮助,我也在我的项目中使用了这个。

关于cocoa - UIPickerView 不允许通过委托(delegate)的 `attributedTitleForRow...` 更改字体名称和大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27455345/

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