gpt4 book ai didi

ios - uipickerview textcolor 问题和颜色亮度问题

转载 作者:行者123 更新时间:2023-12-01 17:53:08 31 4
gpt4 key购买 nike

对于我的 uipickerview,我有:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {

CGSize size = [pickerView rowSizeForComponent:0];
UILabel *labelMain = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
labelMain.backgroundColor = [UIColor clearColor];
labelMain.font = [UIFont fontWithName:kFontSegoeSemiBold size:14];
labelMain.textColor = kColor_default_orangeText;
labelMain.textAlignment = NSTextAlignmentCenter;

int age;
// from
if (pickerView == self.pickerFrom) {
age = minAge + row;
}
// to
else {
age = minAge_pickerTo + row;
}
labelMain.text = [NSString stringWithFormat:@"%d", age];
return labelMain;
}

我知道如何制作蓝色选择指示器(我将蓝色 View 放在 uipickerview 后面并将标签背景颜色设置为 clearColor。

我需要这个选择器(从/到年龄选择器)(蓝色垂直线仅用于 Photoshop):
enter image description here

现在我已经创建了这个选择器:

enter image description here

我有 1 个问题:

我想在选择指示器(或选择器 View 的中心)的区域中使用白色文本颜色,在选择器 View 的其他区域中使用橙色文本颜色。是否可以?

最佳答案

试试这个:

#pragma mark - UIPickerViewDelegate
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{

UILabel *label = (UILabel *)[self.yourPickerOutlet viewForRow:row forComponent:component];

label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor blueColor];
}

#pragma mark PickerView DataSource
- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{

return [dataSourseArray count];
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{


NSString* itemString = dataSourseArray[row];

UILabel *label;

if(view==nil){
label = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 310, 30)];
label.textColor = [UIColor blackColor];
label.backgroundColor = [UIColor clearColor];
label.shadowColor = [UIColor whiteColor];
label.shadowOffset = CGSizeMake(0,1);
label.textAlignment = NSTextAlignmentCenter;
}else{
label = (UILabel*) view;
}



label.text = itemString;


return label;

}

关于ios - uipickerview textcolor 问题和颜色亮度问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23387213/

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