- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return self.data.count;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return self.data[row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {
return 70;
}
- (UIView *)pickerView:(UIPickerView *)pickerView
viewForRow:(NSInteger)row forComponent:(NSInteger)component
reusingView:(UIView *)view {
//普通状态的颜色
UILabel *normal = (UILabel*)view;
if (!normal){
normal = [[UILabel alloc] init];
normal.textColor = [UIColor lightGrayColor];
normal.textAlignment = NSTextAlignmentCenter;
normal.font = [UIFont systemFontOfSize:30];
}
normal.text = [self pickerView:pickerView titleForRow:row forComponent:component];
//当前选中的颜色
UILabel *select = (UILabel*)[pickerView viewForRow:row forComponent:0];
if (select) {
select.textColor = [UIColor redColor];
select.textAlignment = NSTextAlignmentCenter;
select.font = [UIFont systemFontOfSize:60];
}
//下一个选中的颜色
UILabel *selectNext = (UILabel*)[pickerView viewForRow:row + 1 forComponent:0];
if (selectNext) {
selectNext.textColor = [UIColor lightGrayColor];
selectNext.textAlignment = NSTextAlignmentCenter;
selectNext.font = [UIFont systemFontOfSize:30];
}
//设置分割线
for (UIView *line in pickerView.subviews) {
if (line.frame.size.height < 1) {//0.6667
line.backgroundColor = [UIColor clearColor];
}
}
return normal;
}