Giter Club home page Giter Club logo

jblayoutconstrainttool's Introduction

JBLayoutConstraintTool(UIView+Constraint)

Overview

UIView+Constraint,提供一个工具类,封装了对原生NSLayoutConstraint约束的修改API。使修改约束更加方便快捷。

Usage

#import "UIView+Constraint.h"


/**
 *  init and layout subview
 */
- (UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] init];
        [self.view addSubview:_lineView];

        [_lineView setTranslatesAutoresizingMaskIntoConstraints:NO];
        NSLayoutConstraint *originYConstraint = [NSLayoutConstraint constraintWithItem:_lineView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:100];
        NSLayoutConstraint *originXConstraint = [NSLayoutConstraint constraintWithItem:_lineView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:200];
        NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:_lineView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:10];
        NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:_lineView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:200];
        heightConstraint.identifier = @"bounds_height";

        NSArray *arr = [NSArray arrayWithObjects:originYConstraint, originXConstraint, widthConstraint, heightConstraint, nil];
        [self.view addConstraints:arr];
    }

    return _lineView;
}


/**
 *  update constraints
 */
- (void)updateConstraint{

    //根据identifier更新高度约束
    [self.view updateConstraintWithIdentifier:@"bounds_height" constant:100 successBlock:^{
    NSLog(@"success");
    } failureBlock:^{
    NSLog(@"failure");
    }];

    //更新view的top约束
    [self.lineView updateTopConstraint:300 secondItem:self.view secondAttribute:NSLayoutAttributeTop topView:self.view successBlock:^{
    NSLog(@"success");
    } failurdBlock:^{
    NSLog(@"failure");
    }];

    //更新view的left约束
    [self.lineView updateLeftConstraint:300 secondItem:self.view secondAttribute:NSLayoutAttributeLeft topView:self.view successBlock:^{
    NSLog(@"success");
    } failurdBlock:^{
    NSLog(@"failure");
    }];

    //更新view的宽度约束
    [self.lineView updateWidthConstraint:50 topView:self.view successBlock:^{
    NSLog(@"success");
    } failurdBlock:^{
    NSLog(@"failure");
    }];

    //更新view的高度约束
    [self.lineView updateHeightConstraint:50 topView:self.view successBlock:^{
    NSLog(@"success");
    } failurdBlock:^{
    NSLog(@"failure");
    }];

    //更新view的size约束
    [self.lineView updateSizeConstraint:CGSizeMake(50, 50) topView:self.view successBlock:^{
    NSLog(@"success");
    } failurdBlock:^{
    NSLog(@"failure");
    }];

    //更新view的Center_X
    [self.lineView updateCenterXConstraint:40 topView:self.view successBlock:^{
    NSLog(@"success");
    } failurdBlock:^{
    NSLog(@"failure");
    }];

    //更新view的Center_Y
    [self.lineView updateCenterYConstraint:40 topView:self.view successBlock:^{
    NSLog(@"success");
    } failurdBlock:^{
    NSLog(@"failure");
    }];

    //更新view的Center
    [self.lineView updateCenterConstraint:CGPointMake(40, 40) topView:self.view successBlock:^{
    NSLog(@"success");
    } failurdBlock:^{
    NSLog(@"failure");
    }];

}

jblayoutconstrainttool's People

Contributors

jaybinhe avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.