我想实现选择指标的风格如下图所示: -
以下是我的代码: -
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel* tView = (UILabel*)view;
if (!tView)
{
tView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, pickerView.frame.size.width, pickerView.frame.size.height)];
[tView setFont:[UIFont fontWithName:APP_FONT_OPENSANS_LIGHT size:18]];
[tView setTextColor:[UIColor colorWithRed:65.0f/255.0f green:65.0f/255.0f blue:65.0f/255.0f alpha:1]];
[tView setTextAlignment:NSTextAlignmentCenter];
tView.numberOfLines=1;
}
// Fill the label text here
tView.text=@"Hello Moto";
// pickerView.subviews[1].backgroundColor = [UIColor whiteColor];
// pickerView.subviews[2].backgroundColor = [UIColor whiteColor];
return tView;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
UILabel *labelSelected = (UILabel*)[pickerView viewForRow:row forComponent:component];
labelSelected.layer.cornerRadius = 20.0f;
[labelSelected setBackgroundColor:[UIColor whiteColor]];
}
它没有给我我想要的东西。任何解决方案都非常感谢。