iphone - 组件中带有标签的 UIPickerview 图像

标签 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;
        }
    ...
    }

最佳答案

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

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

关于iphone - 组件中带有标签的 UIPickerview 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4284250/

相关文章:

ios - 防止相机基于地理位置工作(iOS、Android)

ios - 图层 maskToBounds 默认值不起作用

javascript - 无法在 UIWebView 中执行 javascript 函数?

iphone - 委托(delegate)正在通过我的应用程序记录非公开事件 : can those events be detected?

ios - 在类似于App Store "Description"Cell的UITableViewCell中扩展UITextView

iphone - 是否可以设置 XCode 来为我进行引用计数?

ios - 无法创建新的客户端 ID(适用于 iOS SDK 中的 google plus 登录)

iphone - 在 Objective-C 中处理数组的更好方法?

iphone - View 加载后 IBOutlet UITableView 为空

objective-c - NSTextFieldCell 或仅带有垂直文本(和彩色着色)的 NSCell