美文网首页
凹凸累out

凹凸累out

作者: json_jie | 来源:发表于2015-03-11 11:12 被阅读35次
    /**
     *
     */
    
    UIView *viwe1 = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 120, 80)];
    viwe1.backgroundColor = [UIColor redColor];
    viwe1.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:viwe1];
    
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(80, 200, 100, 60)];
    view2.backgroundColor = [UIColor orangeColor];
    view2.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:view2];
    
    
    /**
     *  pppp
     */
    NSLayoutConstraint *view1With = [NSLayoutConstraint constraintWithItem:viwe1 attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:150];
    NSLayoutConstraint *view1Hight = [NSLayoutConstraint constraintWithItem:viwe1 attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:150];
    [viwe1 addConstraint:view1With];
    [viwe1 addConstraint:view1Hight];
    NSLayoutConstraint *view1OriginX = [NSLayoutConstraint constraintWithItem:viwe1 attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1.0 constant:20];
    NSLayoutConstraint *view1OriginY = [NSLayoutConstraint constraintWithItem:viwe1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:100];
    [self.view addConstraint:view1OriginX];
    [self.view addConstraint:view1OriginY];
    
    
    
    NSLayoutConstraint *with = [NSLayoutConstraint constraintWithItem:view2 attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:10];
    [view2 addConstraint:with];
    
        NSLayoutConstraint *higth = [NSLayoutConstraint constraintWithItem:view2 attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:10];
    [view2 addConstraint:higth];
    
    NSLayoutConstraint *originX = [NSLayoutConstraint constraintWithItem:view2 attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:viwe1 attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0];
    NSLayoutConstraint *originY = [NSLayoutConstraint constraintWithItem:view2 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:viwe1 attribute:NSLayoutAttributeBottom multiplier:1.0 constant:120];
    [self.view addConstraint:originX];
    [self.view addConstraint:originY];

    相关文章

      网友评论

          本文标题:凹凸累out

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