更改UIPicker颜色 [英] Change UIPicker color

查看:152
本文介绍了更改UIPicker颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改我的选择器的颜色?

How can I change the color of my picker?

我不想更改字体或文本。我的选择器是填充和工作完全如何我想要的,我想做的是将颜色从黑色更改为我的自定义白色。

I don't wish to change the font or the text. My picker is populate and works exactly how I want it, what I want to do is change the color from black to my custom white.

推荐答案

请参阅: http://makeapppie.com/tag/uipickerview-in -swift /

如果您要更改每个元素的标题颜色,您可以实现:

If you want to change your title color of each element you could implement:

func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
    let titleData = pickerData[row]
    var myTitle = NSAttributedString(string: titleData, attributes: [NSFontAttributeName:UIFont(name: "Georgia", size: 15.0)!,NSForegroundColorAttributeName:UIColor.whiteColor()])
    return myTitle
}

Swift 3: / strong>

Swift 3:

func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
    let titleData = pickerData[row]
    let myTitle = NSAttributedString(string: titleData!, attributes: [NSFontAttributeName:UIFont(name: "Georgia", size: 15.0)!,NSForegroundColorAttributeName:UIColor.white])
    return myTitle
}

这篇关于更改UIPicker颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆