Quantcast
Channel: Active questions tagged uipickerview - Stack Overflow
Viewing all articles
Browse latest Browse all 594

UIPickerView set selected row background color (now also for iOS 14)

$
0
0

I found this code here:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{    UILabel *label = (UILabel*) view;    if (label == nil)    {        label = [[UILabel alloc] init];    }    [label setText:@"Whatever"];    // This part just colorizes everything, since you asked about that.    [label setTextColor:[UIColor whiteColor]];    [label setBackgroundColor:[UIColor blackColor]];    CGSize rowSize = [pickerView rowSizeForComponent:component];    CGRect labelRect = CGRectMake (0, 0, rowSize.width, rowSize.height);    [label setFrame:labelRect];    return label;}

But, as stated in the comments, it has a problem:

It colorizes the labels, but not the picker, itself. So, when you roll to one end or the other, there's a blank spot where you can see the white background.

All I need is to change the background colour of the selected row.


Viewing all articles
Browse latest Browse all 594

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>