iOS AFL代码布局

来源:互联网 发布:大数据分析师工资待遇 编辑:程序博客网 时间:2024/06/02 05:18
////  WCChatViewController.m//  WeChat////  Created by fe on 2016/12/6.//  Copyright © 2016年 fe. All rights reserved.//#import "WCChatViewController.h"#import "WCInputView.h"@interface WCChatViewController ()@property (nonatomic , strong) UITableView *tableView;@property (nonatomic , strong) WCInputView *inputView;@end@implementation WCChatViewController- (void)viewDidLoad {    [super viewDidLoad];        //初始化界面    [self setUpView];}- (void)setUpView{    //代码方式实现自动布局    //创建一个TableView    self.tableView = [[UITableView alloc] init];    self.tableView.backgroundColor = [UIColor redColor];    [self.view addSubview:self.tableView];        //创建一个文本框    self.inputView = [WCInputView inputView];    [self.view addSubview:self.inputView];        //自动布局#warning --使用代码进行自动布局需要设置一下属性为NO,并且在添加到父控件之后设置    self.tableView.translatesAutoresizingMaskIntoConstraints = NO;    self.inputView.translatesAutoresizingMaskIntoConstraints = NO;    //tableView水平方向上的约束    NSDictionary *viewsDic = @{@"tableView":self.tableView,@"inputView":self.inputView};    NSArray *tableViewHConstraint =[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[tableView]-0-|" options:0 metrics:nil views:viewsDic];    [self.view addConstraints:tableViewHConstraint];    //inputView水平方向上的约束    NSArray *inpitViewHConstraint =[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[inputView]-0-|" options:0 metrics:nil views:viewsDic];    [self.view addConstraints:inpitViewHConstraint];        //垂直方向上的约束        NSArray *vConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-64-[tableView]-0-[inputView(50)]-0-|" options:0 metrics:nil views:viewsDic];    [self.view addConstraints:vConstraints];    }- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {    // Get the new view controller using [segue destinationViewController].    // Pass the selected object to the new view controller.}*/@end

0 0
原创粉丝点击