0

是否可以在同一选择器视图中显示行标题和行视图?我想做的是让人们能够为我正在编写的时间表应用程序选择主题房间号和颜色。我希望颜色选择是图像。它显示图像但不显示标题。

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row                
 forComponent:(NSInteger)component
{
   if (component == kSubjects) return [PSubjects objectAtIndex:row];
   if (component == kDay) return [PDays objectAtIndex:row];
   //if (component == kLesson) return [PLessonPeriods objectAtIndex:row];
   return [PRoomChoices objectAtIndex:row];

   NSString *title;
   title = [@"" stringByAppendingFormat:@"%d",row];

   return title;
}

-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:  
 (NSInteger)component reusingView:(UIView *)view
{
     if (component == kLesson) {
     UIImageView *myIcon = [[UIImageView alloc] initWithImage:[PLessonPeriods          
     objectAtIndex:row]];
     [myIcon setFrame:CGRectMake(0, 0, 50, 20)];
     return myIcon;}

     else return 0;

}
4

1 回答 1

0

好吧,我偷偷摸摸地创建了一个 UIView,然后添加了一个 UILabel。

-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    // This returns the images
    if (component == kLesson) {
    UIImageView *myIcon = [[UIImageView alloc] initWithImage:[PLessonPeriods objectAtIndex:row]];
    [myIcon setFrame:CGRectMake(0, 0, 50, 20)];
    return myIcon;}

    // This adds a blank UIIamgeView with a label added as a subview.
    if (component == kSubjects) {
        UIImageView *myIcon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 122, 20)];
        UILabel *myLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 122, 20)];
        myLabel.text = [PSubjects objectAtIndex:row];
        myLabel.backgroundColor = [UIColor clearColor];
        [myIcon addSubview:myLabel];
        return myIcon;
    }
    else return 0;

}

在此处输入图像描述 如果有人知道更简单的方法或可以回答我原来的问题,那将是超级的。

于 2013-06-25T23:45:42.607 回答