0

我正在尝试添加 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];
            }
        }           
    }    

请问有人可以指导我吗?谢谢。

4

1 回答 1

0

尝试这个,

可以直接设置uilabel的backgoundcolor

((UILabel*)label).backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Arrow-down.png"]];
于 2012-12-18T09:33:49.503 回答