I don't use constraints or IB to create views so it's easier to create rects this way. Does it wrong totaly?
@interface Client ()
@property (nonatomic, strong) UITextField *name;
@property (nonatomic, strong) UITextField *phoneNumber;
@property (nonatomic, strong) UITextField *address;
@property (nonatomic, strong) UIButton *submit;
@end
@implementation ClientAddVC
- (void)viewDidLoad {
[super viewDidLoad];
[self createSubviews];
[self createViewsRects:@[_name, _phoneNumber, _address, _submit]];
}
- (void)createSubviews{
_name = [Utility textFieldWithPadding:@"Name" frame:[Utility rectForFormFields]];
_name.delegate = self;
_phoneNumber = [Utility textFieldWithPadding:@"Phone Number" frame:[Utility rectForFormFields]];
_phoneNumber.keyboardType = UIKeyboardTypePhonePad;
_phoneNumber.delegate = self;
_address = [Utility textFieldWithPadding:@"Address" frame:[Utility rectForFormFields]];
_address.delegate = self;
_submit = [UIButton buttonWithType:UIButtonTypeCustom];
[_submit setTitle:@"Submit" forState:UIControlStateNormal];
[_submit addTarget:self action:@selector(saveClient) forControlEvents:UIControlEventTouchUpInside];
_submit.backgroundColor = [[Cache sharedCache]blackColor];
_submit.frame = [Utility rectForFormFields];
[self.view addSubview:_name];
[self.view addSubview:_phoneNumber];
[self.view addSubview:_address];
[self.view addSubview:_specialRequest];
[self.view addSubview:_averageOrderSize];
[self.view addSubview:_submit];
}
- (void)saveClient{
}
- (void)textFieldDidBeginEditing:(UITextField *)textField{
_currentField = textField;
}
- (void)createViewsRects:(NSArray *)views{
CGFloat padding = 16;
CGFloat rowPadding = 8;
CGFloat totalHeight = padding;
for (UIView *view in views) {
CGRect viewRect = view.frame;
viewRect.origin.x = padding;
viewRect.origin.y = totalHeight;
view.frame = viewRect;
totalHeight += (view.frame.size.height + rowPadding);
}
self.bgView.contentSize = CGSizeMake(self.view.frame.size.width, totalHeight);
}
@end