这个问题开始在 iOS7 中使用新的 UIPickerView Controller 发生。要在 UIPickerView Controller 中使用图像,您必须使用委托(delegate)方法返回图像:
pickerView:viewForRow:forComponent:reusingView:
问题是屏幕随后会出现各种奇怪的行为 - 当您在控件上下移动手指时, ImageView 会消失。
最佳答案
这是从 iOS 7.0.2 开始在开发论坛上发布的解决方案:
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
// 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;
}
关于uikit - iOS7 UIPickerView 无法正确显示带有图像的自定义 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19158319/