Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPickerview image with label in component

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;
        }
    ...
    }
like image 526
1110 Avatar asked Nov 26 '10 10:11

1110


1 Answers

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)];
like image 123
Vladimir Avatar answered Sep 18 '22 02:09

Vladimir