我制作了以下代码,在屏幕底部显示标签,具体取决于设备是iphone5还是iphone4 / 4s。
我想知道我有另一种方式......例如自动布局?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
CGRect frame;
if ([UIScreen mainScreen].bounds.size.height == 568) {
frame = CGRectMake(140, 500, 320, 100);
} else {
frame = CGRectMake(140, 410, 320, 100);
}
UILabel *iconAdLabel = [[UILabel alloc]init];
iconAdLabel.frame = frame;
iconAdLabel.font = [[UIFont preferredFontForTextStyle:UIFontTextStyleBody] fontWithSize:11.0];
iconAdLabel.text = @"SOME NICE TEXT HERE";
[self.view addSubview:iconAdLabel];
}
答案 0 :(得分:3)
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UILabel *iconAdLabel = [[UILabel alloc]init];
iconAdLabel.frame = CGRectMake(0,self.view.frame.size.height-100,320,100);
iconAdLabel.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
[self.view addSubview:iconAdLabel];
}
答案 1 :(得分:0)
答案 2 :(得分:0)
您可以使用简单的数学表达式,而不是硬编码值或使用约束和界面构建器:
CGFloat const labelHeight = 100;
CGRect frame = CGRectMake(0, CGRectGetHeight([[UIScreen mainScreen] bounds]) - labelHeight, 320, labelHeight);