7

I have UIPickerView with two columns and in one column I want to display image and label next to it. It works. Display and image and label, just label is under image how to put image on the left, and label on the right side? I tried to changle label align to right but it doesnt work.

    - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row
              forComponent:(NSInteger)component reusingView:(UIView *)view
    {
        if(component == kStateComponent)
        {
        UIImage *img = [UIImage imageNamed:@"rts1.png"];
        UIImageView *temp = [[UIImageView alloc] initWithImage:img];        
        temp.frame = CGRectMake(0, 0, 29, 29);


            UILabel *channelLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];
            channelLabel.text = @"sdfsdfdsf";
            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;
        }
    ...
    }
1110
  • 7,829
  • 55
  • 176
  • 334

1 Answers1

7

Set appropriate frame for your channelLabel. To position it to the left of the imageView set correct frame origin x coordinate value (1st parameter in CGRectMake function), e.g:

UILabel *channelLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 0, 60, 60)];
Vladimir
  • 170,431
  • 36
  • 387
  • 313
  • Thanks a lot :) And one more question is there any way to make uipickerview component list to repeat items in it. For example if there is 10 items in it after 10th to display first item again. Is there any quality tutorial? – 1110 Nov 26 '10 at 10:23
  • see this question for example: http://stackoverflow.com/questions/214441/how-do-you-make-an-uipickerview-component-wrap-around – Vladimir Nov 26 '10 at 12:41