如何在UIpickerView的特定行中插入图像和文本?
我已经实现了以下function:
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view { UIImage *img = [UIImage imageNamed:@"persona.jpeg"]; UIImageView *temp = [[UIImageView alloc] initWithImage:img]; temp.frame = CGRectMake(-70, 10, 60, 40); UILabel *channelLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, -5, 80, 60)]; channelLabel.text = @"persona y"; channelLabel.textAlignment = UITextAlignmentLeft; channelLabel.backgroundColor = [UIColor clearColor]; UIView *tmpView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 110, 60)]; [tmpView insertSubview:temp atIndex:0]; [tmpView insertSubview:channelLabel atIndex:1]; return tmpView; }
结果如下:
我需要插入图像和文本在特定的行,任何想法如何做到这一点?
非常感谢您的帮助。
我的想法是填充一系列的图片和描述来填充UIPickerView
尝试获取您的数据作为NSDictionary
Array
。
字典结构: {Image:<imageName>, LabelText:<labelText>}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view { NSDictionary *dict = [datasourceArray objectAtIndex:row]; UIImage *img = [UIImage imageNamed:[dict valueForKey:@"Image"]]; // get image path from the dictionary UIImageView *temp = [[UIImageView alloc] initWithImage:img]; temp.frame = CGRectMake(-70, 10, 60, 40); UILabel *channelLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, -5, 80, 60)]; channelLabel.text = [dict valueForKey:@"LabelText"]; channelLabel.textAlignment = UITextAlignmentLeft; channelLabel.backgroundColor = [UIColor clearColor]; UIView *tmpView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 110, 60)]; [tmpView insertSubview:temp atIndex:0]; [tmpView insertSubview:channelLabel atIndex:1]; return tmpView; }
- NSURLConnection sendAsynchronousRequest – 与HTTPS通信
- UIDocumentInteractionController日历访问
- iPhone控制台的nslog?
- AVFoundation,如何captureStillImageAsynchronouslyFromConnectionclosures快门声音?
- @synchronized是否保证线程安全?
- 我可以使用iCloud来同步NSUserDefaults plist文件吗?
- dynamic插入更多的UITextFields
- Unremove-able iOS应用程序可能吗?
- 设置对象零与释放+ realloc