我試圖根據一定條件更改viewForRow
中的文本顏色。當我按下按鈕時,視圖會變成不同的顏色,但我還想更改選取器中文本的顏色。我使用'viewForRow'是因爲我有一個自定義視圖。更改UIPickerView pickerView:viewForRow:基於一定條件的屬性
//adds subcategories to the wheel
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, pickerView.frame.size.width, 44)];
label.backgroundColor = [UIColor clearColor];
if (!self.isBackgroundWhite)//Boolean that changes when the background changes
{
NSLog(@"Set white text");
label.textColor = [UIColor whiteColor];
}else{
label.textColor = [UIColor blackColor];
}
if (row == 1) {
label.text = [NSString stringWithFormat:@" %@",[self.servicesArray objectAtIndex:row]];
label.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:18];
}else{
label.text = [NSString stringWithFormat:@" -%@",[self.servicesArray objectAtIndex:row] ];
label.font = [UIFont fontWithName:kAppFont size:16];
}
return label;
}
編輯:感謝@Rich我能夠發現我的問題,我只需要調用[self.pickerView reloadAllComponents]
;
你只想改變文字顏色而沒有別的? – Rich
@僅限yup文本顏色 – DevC