Я внедрил контроллер представления для экрана запуска моего приложения, что видно ниже. Я решил использовать фреймы вместо автозапуска, и мне было интересно, есть ли здесь причина использовать autolayout/constraints.Зачем использовать Autolayout/Constraints вместо рамки и layoutSubviews?
Я не разрешаю ротацию в своем приложении, поэтому я не вижу, какие выгоды я бы использовал из ограничений, и поскольку мне не нравится использовать построитель интерфейсов, я думаю, что код чище/проще с созданием и выкладывая рамки.
Я ценю любой вход - пожалуйста, найдите код ниже.
#import "LaunchViewController.h"
#import "RegisterTableViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface LaunchViewController()
@property (nonatomic) UILabel *appLabel;
@property (nonatomic) UIButton *signUpButton;
@property (nonatomic) UIButton *loginButton;
@end
@implementation LaunchViewController
#pragma mark - UIViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor standardBlackColor];
[self layoutViews];
}
- (void)viewDidAppear {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - UIView
- (void)layoutViews
{
self.appLabel.frame = [self _appLabelFrame];
self.loginButton.frame = [self _loginButtonFrame];
self.signUpButton.frame = [self _signUpButtonFrame];
[self.view addSubview:self.appLabel];
[self.view addSubview:self.loginButton];
[self.view addSubview:self.signUpButton];
}
#pragma mark - Layout
- (CGRect)_appLabelFrame
{
CGFloat x_offset = 0;
CGFloat y_offset = (self.view.frame.size.height/10);
CGFloat width =self.view.frame.size.width;
CGFloat height = 50;
return CGRectMake(x_offset, y_offset, width, height);
}
- (CGRect)_signUpButtonFrame
{
CGFloat height = self.view.frame.size.height/14;
CGFloat x_offset = self.view.frame.size.width/24;
CGFloat y_offset = self.view.frame.size.height - ((height + x_offset));
CGFloat width = self.view.frame.size.width - (2 * x_offset);
return CGRectMake(x_offset, y_offset, width, height);}
- (CGRect)_loginButtonFrame
{
CGFloat height = self.view.frame.size.height/14;
CGFloat x_offset = self.view.frame.size.width/24;
CGFloat y_offset = self.view.frame.size.height - ((2 * height)+(2 * x_offset));
CGFloat width = self.view.frame.size.width - (2 * x_offset);
return CGRectMake(x_offset, y_offset, width, height);
}
#pragma mark - Getters and Setters
- (UILabel *)appLabel
{
if (!_appLabel){
_appLabel = [[UILabel alloc] init];
_appLabel.text = @"iOS APP";
_appLabel.textAlignment = NSTextAlignmentCenter;
[_appLabel setFont:[UIFont appThinTitleFont]];
_appLabel.textColor = [UIColor whiteColor];
}
return _appLabel;
}
- (UIButton *)signUpButton
{
if (!_signUpButton){
_signUpButton = [[UIButton alloc] init];
_signUpButton.backgroundColor = [UIColor darkBlueColor];
[_signUpButton setTitle:@"SIGN UP" forState:UIControlStateNormal];
[_signUpButton.titleLabel setFont:[UIFont largeRegularButtonFont]];
[_signUpButton addTarget:self action:@selector(signupPageSegue) forControlEvents:UIControlEventTouchUpInside];
}
return _signUpButton;
}
- (UIButton *)loginButton
{
if (!_loginButton){
_loginButton = [[UIButton alloc] init];
_loginButton.backgroundColor = [UIColor clearColor];
_loginButton.layer.borderColor = [[UIColor whiteColor] CGColor];
_loginButton.layer.borderWidth =1.0f;
[_loginButton setTitle:@"LOGIN" forState:UIControlStateNormal];
[_loginButton.titleLabel setFont:[UIFont largeRegularButtonFont]];
[_loginButton addTarget:self action:@selector(loginPageSegue) forControlEvents:UIControlEventTouchUpInside];
}
return _loginButton;
}
#pragma mark - Targets
- (void)signupPageSegue
{
[self performSegueWithIdentifier:@"SignUpSegue" sender:self];
}
- (void)loginPageSegue
{
[self performSegueWithIdentifier:@"LoginSegue" sender:self];
}
@end
Любые предложения по обучению интерфейсного строителя? Я понимаю ограничения программно – user3298872
Что вы подразумеваете под новыми требованиями на поверхности? – user3298872
+1 к этому ответу, я делал все программно, но гораздо лучше сделать этот тип вещей в раскадровки –