【问题标题】:UIPickerview image with label in component组件中带有标签的 UIPickerview 图像
【发布时间】:2010-11-26 10:02:03
【问题描述】:

我有两列的 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;
        }
    ...
    }

【问题讨论】:

    标签: iphone objective-c


    【解决方案1】:

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

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

    【讨论】:

    • 非常感谢 :) 还有一个问题是有什么方法可以让 uipickerview 组件列表重复其中的项目。例如,如果在 10 日之后有 10 个项目,则再次显示第一个项目。有没有质量教程?
    • 例如看这个问题:stackoverflow.com/questions/214441/…
    猜你喜欢
    • 1970-01-01
    • 2013-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-17
    • 2014-08-30
    • 2016-03-24
    相关资源
    最近更新 更多