我的 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/