【发布时间】:2016-03-31 07:00:40
【问题描述】:
我正在开发只能水平工作并以编程方式完成所有工作的应用程序。
我有一个图像视图、两个文本字段和两个按钮,但我不知道如何对这些文本字段和按钮设置约束,这意味着当我在 iPhone 5s 中使用时很好,但是当我使用 iPhone 6s plus 时然后它看起来很小。 我在这里发布一些代码和屏幕截图
UIImageView *logoImage = [[UIImageView alloc]init];
logoImage.frame = CGRectMake(CGRectGetMidX(self.view.frame)-100, 10, 250, 100);
[logoImage setImage:[UIImage imageNamed:@"antya_logo1.png"]];
[self.view addSubview:logoImage];
UILabel *loginLabel = [[UILabel alloc]init];
loginLabel.frame = CGRectMake(10, 0, 100, 40);
loginLabel.text = @"Login Form";
loginLabel.textColor = [UIColor blackColor];
loginLabel.font = [UIFont fontWithName:@"LaoSangamMN" size:18];
CGFloat Xuser = CGRectGetMidX(self.view.frame)-120;
CGFloat Yuser = CGRectGetMaxY(loginLabel.frame)+80;
usernameField = [[UITextField alloc]init];
usernameField.frame = CGRectMake(Xuser, Yuser, 300, 35);
usernameField.placeholder = @" User Name";
usernameField.font = [UIFont fontWithName:@"LaoSangamMN" size:18];
usernameField.backgroundColor = [UIColor whiteColor];
usernameField.layer.cornerRadius = 7;
usernameField.layer.borderWidth = 0.5;
[self.view addSubview:usernameField];
UIImageView *userImgV = [[UIImageView alloc]init];
userImgV.frame = CGRectMake(CGRectGetMinX(usernameField.frame)-35, CGRectGetMinY(usernameField.frame)+5, 25, 25);
[userImgV setImage:[UIImage imageNamed:@"user-icon.png"]];
[self.view addSubview:userImgV];
CGFloat Ypass = CGRectGetMaxY(usernameField.frame)+20;
passwordField = [[UITextField alloc]init];
passwordField.frame = CGRectMake(Xuser, Ypass, 300, 35);
passwordField.placeholder = @" Password";
passwordField.secureTextEntry = YES;
passwordField.font = [UIFont fontWithName:@"LaoSangamMN" size:18];
passwordField.backgroundColor = [UIColor whiteColor];
passwordField.layer.cornerRadius = 7;
passwordField.layer.borderWidth = 0.5;
[self.view addSubview:passwordField];
这是在iphone5s中
请帮助我,提前谢谢
【问题讨论】:
-
您是否设置了任何限制?如果不是首先尝试一些东西......
-
您需要将代码从使用特定大小切换到使用约束。查看视图锚点,它们是最容易使用的。然后当你遇到困难时回来问一些更具体的问题。最后,以编程方式做所有事情是了解事物如何工作的好方法。但是使用 xib 或故事板将为您节省大量代码和精力。特别是考虑到这种布局是多么简单。
-
不,我没有使用任何约束,我不知道如何以编程方式使用,因此我在这里问,我只水平制作这个应用程序
-
有很多教程可以帮助您...当您对自动布局有更具体的问题时回来
-
@AayushKatiyar 同意 Fonix,如果你想以编程方式使用约束,我建议在这里理解 VFL 是一个很好的起点:commandshift.co.uk/blog/2013/01/31/…
标签: ios objective-c autolayout constraints