UIPickerview图像与组件中的标签

时间:2010-11-26 10:02:04

标签: iphone objective-c

我有UIPickerView有两列,在一列中我想在它旁边显示图像和标签。有用。显示和图像和标签,只是标签在图像下如何将图像放在左侧,标签在右侧?我试图将标签对齐变为正确,但它不起作用。

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

1 个答案:

答案 0 :(得分:7)

为channelLabel设置适当的框架。要将它定位在imageView的左侧,请设置正确的帧原点x坐标值(CGRectMake函数中的第一个参数),例如:

UILabel *channelLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 0, 60, 60)];