在我的应用程序中不使用自动布局和大小类。以编程方式创建所有元素。ios:如何设置所有iphone屏幕的动态高度
计算每个元素的视图宽度和设置框架。在这里我的代码。
UILabel* TitleLbl = [[UILabel alloc] initWithFrame:CGRectMake((self.view.frame.size.width/2)-25,y,100, 50)];
[email protected]"Login";
TitleLbl.textColor=[UIColor whiteColor];
TitleLbl.font = [UIFont boldSystemFontOfSize:14.0];
[self.view addSubview:TitleLbl];
y=y+30;
UILabel* AccountLbl = [[UILabel alloc] initWithFrame:CGRectMake((self.view.frame.size.width/2)-130,y,350, 50)];
[email protected]"Login or Create Your New Account";
AccountLbl.textColor=[UIColor whiteColor];
AccountLbl.font = [UIFont boldSystemFontOfSize:16.0];
[self.view addSubview:AccountLbl];
y=y+40;
UIButton *LoginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
// [LoginBtn addTarget:self action:@selector(aMethod:)
// forControlEvents:UIControlEventTouchUpInside];
[LoginBtn setTitle:@"Login" forState:UIControlStateNormal];
LoginBtn.frame = CGRectMake(self.view.frame.origin.x+40,y, self.view.frame.size.width-80, (self.view.frame.size.height/10));
LoginBtn.layer.cornerRadius = 10;
LoginBtn.layer.borderWidth=1.0f;
LoginBtn.layer.borderColor = [UIColor whiteColor].CGColor;
LoginBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
LoginBtn.titleLabel.font = [UIFont systemFontOfSize:16.0];
//LoginBtn.backgroundColor=[UIColor orangeColor];
[self.view addSubview:LoginBtn];
UIButton *RegBtn = [UIButton buttonWithType:UIButtonTypeCustom];
// [RegBtn addTarget:self action:@selector(aMethod:)
// forControlEvents:UIControlEventTouchUpInside];
[RegBtn setTitle:@"Register Now" forState:UIControlStateNormal];
RegBtn.frame = CGRectMake(self.view.frame.origin.x+40, y, self.view.frame.size.width-80, (self.view.frame.size.height/10));
RegBtn.layer.cornerRadius = 10;
RegBtn.layer.borderWidth=1.0f;
RegBtn.layer.borderColor = [UIColor whiteColor].CGColor;
RegBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
RegBtn.titleLabel.font = [UIFont systemFontOfSize:16.0];
[self.view addSubview:RegBtn];
我该如何为此代码计算动态heigth。 特别是 UIButton * RegBtn,UIButton * LoginBtn这两个按钮我不能够把动态高度。
任何人都可以帮助我。如何计算动态高度。为我提供任何解决方案。感谢提前。
如何添加高度。 –
@saravanaa'[UIscreen mainScreen] .bounds.height' –