【发布时间】:2011-07-27 19:06:41
【问题描述】:
有谁知道是否可以更改单个 UIPickerView 项的字体和/或颜色?
【问题讨论】:
标签: iphone cocoa-touch ios ipad
有谁知道是否可以更改单个 UIPickerView 项的字体和/或颜色?
【问题讨论】:
标签: iphone cocoa-touch ios ipad
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UILabel* tView = (UILabel*)view;
if (!tView){
tView = [[UILabel alloc] init];
// Setup label properties - frame, font, colors etc
...
}
// Fill the label text here
...
return tView;
}
【讨论】:
是的,这是可能的。为此,您需要在选择器的委托中实现 pickerView:viewForRow:forComponent:reusingView: 方法 - 在此处创建 UILabel 实例并使用您想要的任何属性对其进行设置。
【讨论】:
为此,我会简单地使用属性字符串。
实现这个方法是你的委托:
- (NSAttributedString *)pickerView:(UIPickerView *)pickerView
attributedTitleForRow:(NSInteger)row
forComponent:(NSInteger)component
【讨论】: