企业信息

    北京沃赢科技有限公司

  • 11
  • 公司认证: 营业执照已认证
  • 企业性质:
    成立时间:
  • 公司地址: 北京市 海淀区 海淀街道 北京市海淀区银海大厦
  • 姓名: 刘老师
  • 认证: 手机未认证 身份证未认证 微信未绑定

    IOS自动布局

  • 所属行业:商务服务 教育培训 管理培训
  • 发布日期:2015-08-19
  • 阅读量:205
  • 价格:面议
  • 产品规格:不限
  • 产品数量:10000.00 套
  • 包装说明:不限
  • 发货地址:北京海淀海淀  
  • 关键词:我赢职场,在线教育,iOS

    IOS自动布局详细内容

    IOS自动布局
    
    我赢职场课程简介
    自动布局在iOS 6.0中引入,仅可以支持IOS6.0 及 更高版本。它可以帮助我们创建用于多个种设备的界面。
    实例步骤
    1.创建一个简单的 View based application
    2.修改 ViewController.m 的文件内容,如下所示
    #import "ViewController.h"@interface ViewController ()@property (nonatomic, strong) UIButton *leftButton;@property (nonatomic, strong) UIButton *rightButton;@property (nonatomic, strong) UITextField *textfield;@end@implementation ViewController- (void)viewDidLoad{    [super viewDidLoad];    UIView *superview = self.view;    /*1. Create leftButton and add to our view*/    self.leftButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];    self.leftButton.translatesAutoresizingMaskIntoConstraints = NO;    [self.leftButton setTitle:@"LeftButton" forState:UIControlStateNormal];    [self.view addSubview:self.leftButton];        /* 2. Constraint to position LeftButton's X*/    NSLayoutConstraint *leftButtonXConstraint = [NSLayoutConstraint     constraintWithItem:self.leftButton attribute:NSLayoutAttributeCenterX     relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:superview attribute:    NSLayoutAttributeCenterX multiplier:1.0 constant:-60.0f];    /* 3. Constraint to position LeftButton's Y*/    NSLayoutConstraint *leftButtonYConstraint = [NSLayoutConstraint     constraintWithItem:self.leftButton attribute:NSLayoutAttributeCenterY     relatedBy:NSLayoutRelationEqual toItem:superview attribute:    NSLayoutAttributeCenterY multiplier:1.0f constant:0.0f];       /* 4. Add the constraints to button's superview*/    [superview addConstraints:@[ leftButtonXConstraint,    leftButtonYConstraint]];        /*5. Create rightButton and add to our view*/    self.rightButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];    self.rightButton.translatesAutoresizingMaskIntoConstraints = NO;    [self.rightButton setTitle:@"RightButton" forState:UIControlStateNormal];    [self.view addSubview:self.rightButton];        /*6. Constraint to position RightButton's X*/    NSLayoutConstraint *rightButtonXConstraint = [NSLayoutConstraint     constraintWithItem:self.rightButton attribute:NSLayoutAttributeCenterX     relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:superview attribute:    NSLayoutAttributeCenterX multiplier:1.0 constant:60.0f];    /*7. Constraint to position RightButton's Y*/    rightButtonXConstraint.priority = UILayoutPriorityDefaultHigh;    NSLayoutConstraint *centerYMyConstraint = [NSLayoutConstraint     constraintWithItem:self.rightButton attribute:NSLayoutAttributeCenterY     relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:superview attribute:    NSLayoutAttributeCenterY multiplier:1.0f constant:0.0f];    [superview addConstraints:@[centerYMyConstraint,    rightButtonXConstraint]];   //8. Add Text field    self.textfield = [[UITextField alloc]initWithFrame:    CGRectMake(0, 100, 100, 30)];    self.textfield.borderStyle = UITextBorderStyleRoundedRect;    self.textfield.translatesAutoresizingMaskIntoConstraints = NO;    [self.view addSubview:self.textfield];    //9. Text field Constraints    NSLayoutConstraint *textFieldTopConstraint = [NSLayoutConstraint     constraintWithItem:self.textfield attribute:NSLayoutAttributeTop     relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:superview     attribute:NSLayoutAttributeTop multiplier:1.0 constant:60.0f];    NSLayoutConstraint *textFieldBottomConstraint = [NSLayoutConstraint     constraintWithItem:self.textfield attribute:NSLayoutAttributeTop     relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:self.rightButton     attribute:NSLayoutAttributeTop multiplier:0.8 constant:-60.0f];    NSLayoutConstraint *textFieldLeftConstraint = [NSLayoutConstraint     constraintWithItem:self.textfield attribute:NSLayoutAttributeLeft     relatedBy:NSLayoutRelationEqual toItem:superview attribute:    NSLayoutAttributeLeft multiplier:1.0 constant:30.0f];    NSLayoutConstraint *textFieldRightConstraint = [NSLayoutConstraint     constraintWithItem:self.textfield attribute:NSLayoutAttributeRight     relatedBy:NSLayoutRelationEqual toItem:superview attribute:    NSLayoutAttributeRight multiplier:1.0 constant:-30.0f];    [superview addConstraints:@[textFieldBottomConstraint ,    textFieldLeftConstraint, textFieldRightConstraint,     textFieldTopConstraint]];   }- (void)didReceiveMemoryWarning{    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end
    
    学习链接/ios/?tg=5009295340
    学习交流群:317140762
    

    http://jiexiaotan.cn.b2b168.com
    欢迎来到北京沃赢科技有限公司网站, 具体地址是北京市海淀区海淀街道北京市海淀区银海大厦,联系人是刘老师。 主要经营iOS开发、互联网架构师、安卓、Oracle、SAP、RedHat等。 单位注册资金未知。 我们公司主要服务有:教育教学软件等,我们愿以优质的服务和诚意、为您提供精良的产品和专业枝术,共创美好未来!