BYViewConstraint 0.6.0

BYViewConstraint 0.6.0

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2015年4月

Moicci维护。



  • By
  • moicci

BYViewConstraint 是一个方便的类,用于在 Objective-C 中实现以下“Auto Layout”。

    UILabel* topLabel = [self addLabel:@"fullWidth/top" backColor:[UIColor redColor]];
    UILabel* bottomLabel = [self addLabel:@"fullWidth/bottom" backColor:[UIColor redColor]];
    UILabel* centerLabel = [self addLabel:@"centerX/Y" backColor:[UIColor blueColor]];
    UILabel* leftLabel = [self addLabel:@"left" backColor:[UIColor greenColor]];
    UILabel* rightLabel = [self addLabel:@"right" backColor:[UIColor greenColor]];

    BYViewConstraint* constraint = [[BYViewConstraint alloc] initWithSuperview:self.view];

    [constraint view:topLabel];
    [constraint fullWidth];
    [constraint top];
    [constraint height:50];

    [constraint view:bottomLabel];
    [constraint fullWidth];
    [constraint bottom];
    [constraint height:50];

    [constraint view:centerLabel];
    [constraint centerX];
    [constraint centerY];
    [constraint width:150];
    [constraint height:150];

    [constraint view:leftLabel];
    [constraint attachTop:topLabel];
    [constraint attachBottom:bottomLabel];
    [constraint left];
    [constraint attachRight:centerLabel];

    [constraint view:rightLabel];
    [constraint attachTop:topLabel];
    [constraint attachBottom:bottomLabel];
    [constraint attachLeft:centerLabel];
    [constraint right];

    [constraint apply];

或在 Swift 中。

let topLabel = addLabel("fullWidth/top", backColor:UIColor.redColor())
let bottomLabel = addLabel("fullWidth/bottom", backColor:UIColor.redColor())
let centerLabel = addLabel("centerX/Y", backColor:UIColor.blueColor())
let leftLabel = addLabel("left", backColor:UIColor.greenColor())
let rightLabel = addLabel("right", backColor:UIColor.greenColor())

let constraint = BYViewConstraint(superview:self.view)

constraint.view(topLabel)
    .fullWidth()
    .top()
    .height(50)

constraint.view(bottomLabel)
    .fullWidth()
    .bottom()
    .height(50)

constraint.view(centerLabel)
    .centerX()
    .centerY()
    .width(150)
    .height(150)

constraint.view(leftLabel)
    .attachTop(topLabel)
    .attachBottom(bottomLabel)
    .left()
    .attachRight(centerLabel)

constraint.view(rightLabel)
    .attachTop(topLabel)
    .attachBottom(bottomLabel)
    .attachLeft(centerLabel)
    .right()

constraint.apply()

使用方法

要运行示例项目,首先从仓库中克隆,然后从 Example 目录中运行 pod install

如果您通过 CocoaPods 安装此库,请从 https://github.com/moicci/BYViewConstraint 克隆 Example 的 repo。

  • 对于 Swift 用户:请参阅 'SwiftDemo' 子目录中的 ViewController.swift。
  • 对于 Objective-C 用户:请参阅 'ObjcDemo' 子目录中的 ViewController.m。

安装

然后安装 pod。

pod install

对 Swift 项目

  • import "BYViewConstraint.h" 添加到您的 Objective-C 桥接头文件 (-Bridging-Header.h)。

对 Objective-C 项目

  • 在您的 .m 文件中使用 BYViewConstraint 时,请添加 #import "BYViewConstraint.h"

作者

Moicci 在 blevlo media inc。

许可证

BYViewConstraint 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。