使用代码实现autolayout

作者: _君莫笑_ | 来源:发表于2016-10-20 08:56 被阅读23次
    //|:表示父视图
    
    //_:表示的是距离
    
    //v:表示垂直方向
    
    //H:表示水平方向
    
    //>=:表示视图间距,宽度和高度必须大于或等于某个值
    
    //<=:表示视图距离,宽度和高度必须小于或等于某个值
    
    //==:表示视图间距,宽度或高度必须等于某个值
    
    UIButton*button1 = [UIButtonbuttonWithType:UIButtonTypeSystem];
    
    button1.backgroundColor= [UIColoryellowColor];
    
    [button1setTitle:@"Click"forState:UIControlStateNormal];
    
    [button1setTranslatesAutoresizingMaskIntoConstraints:NO];//标记是否自动布局
    
    [self.viewaddSubview:button1];
    
    UIButton*button2 = [UIButtonbuttonWithType:UIButtonTypeSystem];
    
    [button2setBackgroundColor:[UIColorredColor]];
    
    [button2setTitle:@"Click Me"forState:UIControlStateNormal];
    
    [self.viewaddSubview:button2];
    
    NSDictionary*views =NSDictionaryOfVariableBindings(button1, button2);
    
    [self.viewaddConstraints:[NSLayoutConstraintconstraintsWithVisualFormat:@"H:|-(==50)-[button1(100)]"options:0metrics:nilviews:views]];
    

    相关文章

      网友评论

        本文标题:使用代码实现autolayout

        本文链接:https://www.haomeiwen.com/subject/jwlfuttx.html