我正在尝试添加 UIImageView 以及UISegmentedControl
. 请注意,我不想将图像设置为背景,并且我已经在 IB 中获得了分段控制。到目前为止,我尝试过的是:
for (id segment in [segmentControl subviews])
{
for (id label in [segment subviews])
{
if ([label isKindOfClass:[UILabel class]])
{
float width = ((UILabel*)label).bounds.size.width;
UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Arrow-down.png"]];
image.frame = CGRectMake(width + 2, 15 , 32, 32);
((UILabel*)label).frame = CGRectMake(((UILabel*)label).frame.origin.x,((UILabel*)label).frame.origin.y, width + image.frame.size.width + 5, ((UILabel*)label).frame.size.height);
[(UILabel*)label insertSubview:image atIndex:0];
}
}
}
请问有人可以指导我吗?谢谢。