I have a pickerView to which I add a custom view to each row by viewForRow delegate method. The goal here is to have a different view for the center(selected) row like a highlight view WHILE the pickerView spins (a center static view). Any help would be appreciated..
Asked
Active
Viewed 802 times
1 Answers
2
In iOS 7, you can do this adding a subview to your UIPickerView
. In earlier versions, it will be such a painful operation because UIPickerView
will have a border etc, so probably you will need a custom picker-like implementation.
For iOS 7, you can use something like below:
CGFloat rowHeight = 100; // rowHeight of your picker view, i assumed your rowHeight equals to 100
// Create a custom view, centered vertically in your picker view
UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0,
(pickerView.bounds.size.height - rowHeight)/2,
pickerView.bounds.size.width,
rowHeight)];
[view setBackgroundColor:[UIColor clearColor]];
// Do some highlighting operations
[view.layer setCornerRadius:5.0];
[view.layer setBorderColor:[UIColor blueColor].CGColor];
[view.layer setBorderWidth:5.0];
[pickerView addSubview:view];

ismailgulek
- 1,029
- 1
- 11
- 8
-
Oh I get the thinking behind it.Do you think there is a way of adjusting the customView of the row in view before is set selected? Because for a row to be selected it has to stop the scrolling animation. for example changing the font or color or text size inside the customView.. I mean while Scrolling – snksnk Mar 30 '14 at 12:34
-
You can try subclassing `UIPickerView` and overriding `selectRow:inComponent:animated:` method. After calling `super`, maybe you will be able to customize your view. – ismailgulek Mar 30 '14 at 12:39