UIPickerView Row Color

后端 未结 5 1702
Happy的楠姐
Happy的楠姐 2021-02-15 17:04

Does anyone know how to change the color of a row (or row background) in the UIPickerView control from the iPhone SDK? Similiar to the below title for row, however I would also

5条回答
  •  故里飘歌
    2021-02-15 17:19

    -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    
        UILabel *labelSelected = (UILabel*)[pickerView viewForRow:row forComponent:component];
        [labelSelected setTextColor:[UIColor redColor]];
    
    }
    

    And

    - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    
        UILabel *label = (id)view;
    
        if (!label){
    
          label=[[UILabel alloc]init];
          label.textAlignment = NSTextAlignmentCenter;
          pickerView.backgroundColor=[UIColor whiteColor];
          label.text=[self pickerView:pickerView titleForRow:row forComponent:component];
          label.textColor=[UIColor grayColor];
    
        }
        return label;
    }
    

提交回复
热议问题