Reputation: 891
I have a problem with UIPickerView...
I created a UIPickerView with two components with two rows for the first one, and three rows for the second one. I'm trying to create a custom view for each row in each component. Okay, I've subclassed UIView and added one UIImageView and one UILabel.
I've used the - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
method to create the custom view and it seems to work ok.
But when each row "enters" the middle area of the UIPickerView, all the content disappears!
Here's an image:
Anyone with ideas?
Upvotes: 1
Views: 400
Reputation: 111
I had a similar problem, and found the solution on stackoverflow-but I can't find the link, so I included the code below. to be clear-I am not claiming this code as my own. If anyone finds the original answer, vote their answer up
// self.myImages is an array of UIImageView objects
UIView * myView = [self.myImages objectAtIndex:row];
// first convert to a UIImage
UIGraphicsBeginImageContextWithOptions(myView.bounds.size, NO, 0);
[myView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// then convert back to a UIImageView and return it
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
return imageView;
Upvotes: 1