MXAutoLayout 2.2.0

MXAutoLayout 2.2.0

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布上次发布2016年9月

Meniny 维护。



  • 作者
  • Elias Abel

MXAutoLayout-in-Objective-C

MXAutoLayout 是一个适用于 iOS 平台的令人愉快的布局框架。

使用方法

#import "MXAutoLayout.h"
// Sample:
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIButton *buttonTop = [UIButton new];
    [buttonTop setBackgroundColor:[UIColor redColor]];
    [buttonTop addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [[self view] addSubview:buttonTop];

    UIButton *buttonInside = [UIButton new];
    [buttonInside setBackgroundColor:[UIColor purpleColor]];
    [buttonInside addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [[self view] addSubview:buttonInside];

    UIButton *buttonBottom = [UIButton new];
    [buttonBottom setBackgroundColor:[UIColor greenColor]];
    [buttonBottom addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [[self view] addSubview:buttonBottom];

    CGFloat margin = 8;

    // AutoLayout
    [buttonTop alignLeftToLayoutPosition:margin];
    [buttonTop alignRightToSuperviewWithPadding:margin];
    [buttonTop alignTopToLayoutPosition:margin];

    [buttonBottom alignBelowView:buttonTop withPadding:margin];
    [buttonBottom alignLeftToView:buttonTop padding:0];
    [buttonBottom matchSizeToView:buttonTop withExtensions:CGSizeZero];
    [buttonBottom alignBottomToSuperviewWithPadding:margin];

    [buttonInside matchBoundsToView:buttonTop edgeInsets:UIEdgeInsetsMake(15, 15, 15, 15)];
}

- (void)buttonAction:(UIButton *)sender {
    CGFloat hue = ( arc4random() % 256 / 256.0 ); //0.0 to 1.0
    CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0,away from white
    CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; //0.5 to 1.0,away from black
    UIColor *color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
    [sender setBackgroundColor:color];
    NSLog(@"%@", sender.backgroundColor);
}