UIPickerView Row Color

后端 未结 5 1689
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:29

    Thanks Noah, that's exactly what I needed. I wanted to add the code here just in case anyone else needs (or wants to comment on :)

    - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
    
        CGRect imageFrame = CGRectMake(0.0, 0.0, 15, 15);
        UIImageView *label = [[[UIImageView alloc] initWithFrame:imageFrame] **autorelease**];
    
        if (row == 0)
        {
            label.backgroundColor = [UIColor redColor];
        }
        if (row == 1)
        {
            label.backgroundColor = [UIColor blueColor];
        }
        if (row == 2)
        {
            label.backgroundColor = [UIColor blackColor];
        }   
        return label;
    }
    

提交回复
热议问题