我希望能够将我的设置UIPickerView
为 1 列和 10 行。在此列中,有一个标题 ( UILabel
) 和旁边的图像(图像是星星,可能有 1-3 颗星)。我已将图像放入一个名为“showImages”的数组中。我已将其UILabels
放入一个NSString
名为“currentNames”的数组中。两个数组的索引相互对应。由于某种原因,我的代码在我实现时不起作用
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row
forComponent:(NSInteger)component reusingView:(UIView *)view
我相信这是因为我使用“行”来索引不正确的数组。有谁知道我怎么能正确地做到这一点?在此先感谢,我的其余代码如下。
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row
forComponent:(NSInteger)component reusingView:(UIView *)view {
NSString *imageName= [imageNames objectAtIndex:row];
if(component == 0)
{
NSString *imageName= [imageNames objectAtIndex:row];
UIImage *img = [UIImage imageNamed:imageName];
UIImageView *temp = [[UIImageView alloc] initWithImage:img];
temp.frame = CGRectMake(120, 15,70, 27);
UILabel *channelLabel = [[UILabel alloc] initWithFrame:CGRectMake(-80, 0, 320, 60)];
channelLabel.text = [currentLottoNames objectAtIndex:row];
channelLabel.textAlignment = UITextAlignmentLeft;
channelLabel.backgroundColor = [UIColor clearColor];
channelLabel.font = [UIFont boldSystemFontOfSize:20];
channelLabel.backgroundColor = [UIColor clearColor];
channelLabel.shadowColor = [UIColor whiteColor];
channelLabel.shadowOffset = CGSizeMake (0,1);
UIView *tmpView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 110, 60)];
[tmpView insertSubview:channelLabel atIndex:0];
[tmpView insertSubview:temp atIndex: 1];
i++;
return tmpView;
}
}