更改 UIPicker 的行颜色或行文本颜色
我有一个 UIPicker,用于打开和关闭图层。我希望能够更改选择器中行的颜色以指示该图层是否打开,或者更改文本的字体颜色以指示该图层是否打开。
如果两者都不可行,我将附加 nsstring 以在返回之前在其末尾添加一个 X(因此,如果图层打开,“街道”将变为“街道 X”)。我也不知道该怎么做。我知道您可以使用数字进行这种类型的抛光,但不确定是否使用 NSString
。我知道选择器可以显示 27 个字符,所以也许将字符串长度设置为 26,然后将位置 26 处的字符设置为 X?但我不知道如何设置字符串的长度。
对于这两条路有什么想法吗?
I have a UIPicker
I'm using to toggle layers on and off. I want to be able to either change the color of a row within the picker to indicate if that layer is on, or to change the font color of the text to indicate if that layer is on.
If neither are possible, I will append the nsstring
to add an X at the end of it before I return it (so "streets" would become "streets X" if the layer is on). I'm not sure how to do this either. I know you can do this type of buffing with a number, but not sure with a NSString
. I know the picker can display 27 characters, so maybe set the string length to 26 and then set the char at location 26 to X? But I don't know how to set the length of a string.
Any ideas for either path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 UIPickerView 中的自定义行,您必须实现
pickerView:viewForRow:forComponent:reusingView:
而不是pickerView:titleForRow:forComponent:
。在您的情况下,您只需使用
UILabel
作为视图,并更改每行的文本颜色和文本字符串。假设您只有一个组件:
For custom rows in a UIPickerView you have to implement
pickerView:viewForRow:forComponent:reusingView:
instead ofpickerView:titleForRow:forComponent:
.In your case you'd just use a
UILabel
as the view, and change the text colour and text string for each row.Assuming you only have one component: