UIPickerView不允许通过委托的“attributTitleForRow ...”更改字体名称和大小 [英] UIPickerView won't allow changing font name and size via delegate's `attributedTitleForRow...`
本文介绍了UIPickerView不允许通过委托的“attributTitleForRow ...”更改字体名称和大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下func来更改字体颜色和字体大小,颜色工作,但字体名称和字体大小拒绝工作。
I use the following func to change the font color and font size, the color works but the font name and font size refuse to work.
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()])
有任何帮助吗?
Thx。
推荐答案
我有另一个选项帮助你。
I have a another option may be it helpfull for you..
做所有需要正常选择器视图的工作:更多帮助 在Swift iOS中执行UIPickerView make
Do all work that need for normal picker view : for more help UIPickerView make in Swift iOS
: - 您可以使用 viewForRow 的方法
Now follow this step : - you can use method of viewForRow like this
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
}
帮助充分,我也在我的项目中使用这个。
May be it help full for you, I also used this in my project.
这篇关于UIPickerView不允许通过委托的“attributTitleForRow ...”更改字体名称和大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文