Custom UIPickerView with Custom Background color

后端 未结 6 589
野的像风
野的像风 2020-12-14 11:31

I have created a sample picker-view which will display some details. Setting the Background color using:

_pickerView.backgroundColor = [UIColor redColor]; 
<         


        
6条回答
  •  别那么骄傲
    2020-12-14 12:18

    You can change selected color by putting tableview cell in it.

    - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
    UITableViewCell *cell = (UITableViewCell *)view;
    
    if( cell == nil ) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
        [cell setBackgroundColor:[UIColor redColor]];
    
        [cell setBounds: CGRectMake(0, 0, cell.frame.size.width -20 , 44)];
        cell.textLabel.text = [self.userNameArray objectAtIndex:row];
        cell.userInteractionEnabled = NO;
    }
    
    return cell;
    }
    

提交回复
热议问题