在我的應用程序中不使用自動佈局和大小類。以編程方式創建所有元素。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' –