2013-06-25 5 views
0

Можно ли отображать заголовок для строки и представления строки в том же представлении выбора? Я хочу, чтобы люди могли выбирать номер комнаты и цвет темы для приложения расписания, которое я пишу. Я хотел, чтобы выбор цвета был изображением. Он показывает изображения, но не названия.UIPickerView - Показать изображения и текст

-(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; 

} 

ответ

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; 

} 

enter image description here Если кто-нибудь знает простой способ или может ответить на мой первоначальный вопрос, который был бы надставок.