我的 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;
}
...
}
为您的频道标签设置适当的框架。要将其定位到 imageView 的左侧,请设置正确的框架原点 x 坐标值(CGRectMake 函数中的第一个参数),例如:
UILabel *channelLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 0, 60, 60)];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)