gpt4 book ai didi

ios - 更改选择器 View 中的行颜色

转载 作者:行者123 更新时间:2023-11-29 04:27:44 24 4
gpt4 key购买 nike

有什么方法可以更改行中选择器 View 对象的颜色吗?

例如,您有 addobject:@"black" 但如何将字体颜色更改为红色?

最佳答案

您不使用“title”委托(delegate)方法,而是使用 UIView 方法,然后创建并填充您自己的 View 。因此,您创建了一个 320 宽、44 高的 UIView,在其中放置一个标签,设置标签文本和颜色,现在您就拥有了您想要的内容。

编辑:

#define PICKER_VIEW_SIZE CGSize(300, 40)

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
return PICKER_VIEW_SIZE.height;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
return PICKER_VIEW_SIZE.width;
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
// assume one component, but this solutions works for multiple
// lets do red, green, and blue alternating backgrounds with alternating black and white text

UIColor *backgroundColor;
switch(row % 3) {
case 0:
default:
backgroundColor = [UICOlor redColor];
break;
case 1:
backgroundColor = [UIColor blueColor];
break;
case 2:
backgroundColor = [UIColor greenColor];
break;
}
UIColor *textColor = (row % 2) ? [UIColor blackColor] : [UIColor whiteColor];

UIView *view = [[UIView alloc] initWithFrame:(CGRect){ {0,0}, PICKER_VIEW_SIZE}];
view.backgroundColor = backgroundColor;

UILabel *label = [UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 20)];
// configure the label
label.text = text appropriate for this row;

[view addSubview:label];

return view;
}

关于ios - 更改选择器 View 中的行颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12099779/

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