iOS - 如何将UIImage和UILabel作为页脚放在同一行?

时间:2012-09-25 16:06:56

标签: iphone ios uiview uiimage uilabel

我需要在我的视图中有一个页脚说“Powered by:{image_logo_of_my_company}”我如何实现这一目标?

1 个答案:

答案 0 :(得分:4)

制作UIView类型的包装器视图,并在该视图内的UILabel内的适当坐标处添加UIImageView和徽标。

UIView *wrapper = [[UIView alloc] initWithFrame:footerFrame]; 
UILabel *label = [[UILabel alloc] initWithFrame:
   CGRectMake(0, 0, footerFrame.size.width*0.6, footerFrame.size.height)];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:
   CGRectMake(footerFrame.size.width*0.6, 0, 
   footerFrame.size.width*(1.0-0.6), footerFrame.size.height)];
[wrapper addSubView:label];
[wrapper addSubView:imageView];
label.text = @"Powered by: ";
imageView.image = [UIImage imageNamed:@"logo"]; // assumes logo.png & logo@2x.png
[viewNeedingFooter addSubView:wrapper]; 

假设您需要标签宽度的60%和徽标的40%。