简体   繁体   中英

How do i remove the blue highlight when selection occurs in a UIPickerView

when i select a cell in my modified picker view, a blue background colour appears. all other treads i have seen do not give me a good answer. anyone has a solution?

pickerView.showsSelectionIndicator = NO;

Just set the UITableViewCell selectionStyle property to UITableViewCellEditingStyleNone

cell.selectionStyle = UITableViewCellEditingStyleNone;

I have add toolbar at the top of picker view and add cutom button as a sub view of toolbar and both picker view and toolbar are add as a subview of Main view so you can handle this.

I've met this one. Let's get a look at it in details. To create your custom picker view, you create your custom UIView class, eg :

@interface TimeAroundView : UIView 
{
    NSString *title;
    UIImage *image;
}
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) UIImage *image;
@end

Then in your custom picker view controller you create some container, eg NSArray, which will get all TimeAroundView objects you want to represent in your picker view. So, for every object you must do

timeAroundViewObject.userInteractionEnabled = NO;

I think -(id)init is the best place for filling that container in, so you get something like this:

- (id)init
{
    self = [super init];
    if (self) {
        // create the data source for this custom picker
        NSMutableArray *viewArray = [[NSMutableArray alloc] init];

        TimeAroundView *earlyMorningView = [[TimeAroundView alloc] initWithFrame:CGRectZero];
        earlyMorningView.title = @"Early Morning";
        earlyMorningView.image = [UIImage imageNamed:@"12-6AM.png"];
        earlyMorningView.userInteractionEnabled = NO;
        [viewArray addObject:earlyMorningView];
        [earlyMorningView release];

        TimeAroundView *lateMorningView = [[TimeAroundView alloc] initWithFrame:CGRectZero];
        lateMorningView.title = @"Late Morning";
        lateMorningView.image = [UIImage imageNamed:@"6-12AM.png"];
        lateMorningView.userInteractionEnabled = NO;
        [viewArray addObject:lateMorningView];
        [lateMorningView release];

        // ....  (more of objects)

        self.customPickerArray = viewArray;
        [viewArray release];
    }

    return self;
}

And in your pickerView:viewForRow:forComponent:reusingView: you just return proper element from array. That works for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM