WHC_AutoLayoutKit_Swift2_3 2.6.6

WHC_AutoLayoutKit_Swift2_3 2.6.6

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Feb 2017
SwiftSwift Version 2.3
SPMSupports SPM

Maintained by netyouli.



  • By
  • 吴海超(WHC)

WHC_AutoLayoutKit

Build Status

  • An use the most simple and powerful open source library automatic layout for iOS.
  • Service to update constraints, convenient and quick dynamic UI layout.
  • 服务于更新约束方便快捷动态UI的自动布局库,支持Cell高度自动,UILabel,ScrollView,UIView高宽自动

使用原理详解

简介

  • 布局Api采用链式调用(快捷方便)
  • 提供【Objective-C】【Swift2.3】【Swift3.0】三种语言版本库
  • 包含一行代码计算UITableViewCell高度模块
  • 包含WHC_StackView模块(目的替代系统UIStackView)
  • 隐式更新约束技术
  • 支持修改约束优先级
  • 支持删除约束
  • 咨询QQ: 712641411
  • 开发作者: 吴海超

要求

  • iOS 6.0 or later
  • Xcode 8.0 or later

集成

  • 使用CocoaPods:

    • 【Objective-C】: pod 'WHC_AutoLayoutKit', '~> 2.6.4'
    • 【Swift3.0】: pod 'WHC_AutoLayoutKit_Swift3', '~> 2.6.5'
    • 【Swift2.3】: pod 'WHC_AutoLayoutKit_Swift2_3', '~> 2.6.5'
  • 手工集成:

    • 【Objective-C】: 导入文件夹WHC_AutoLayoutKit(OC)
    • 【Swift3.0】: 导入文件夹WHC_AutoLayoutKit(Swift3.0)
    • 【Swift2.3】: 导入文件夹WHC_AutoLayoutKit(Swift2.3)

使用

Objective-C版

- (void)viewDidLoad {
    [super viewDidLoad];
    UIView * view = [UIView new];
    [self.view addSubview: view];

    view.whc_LeftSpace(10)
        .whc_TopSpace(10)
        .whc_RightSpaceToView(10,view1)
        .whc_Height(100)
        .whc_PriorityLow() /// height低优先级
}

Swift版

override func viewDidLoad() {
    super.viewDidLoad()
    let view = UIView()
    self.view.addSubview(view)

    view.whc_Left(20)
        .whc_Right(0)
        .whc_Height(40)
        .whc_Top(64)
        .whc_PriorityLow() /// top低优先级
}

ObjectiveC版一行代码计算cell高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [UITableViewCell whc_CellHeightForIndexPath:indexPath tableView:tableView];
}

Swift版一行代码计算cell高度

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return UITableViewCell.whc_CellHeightForIndexPath(indexPath, tableView: tableView)
}

ObjectiveC版WHC_StackView使用

- (void)viewDidLoad {
    [super viewDidLoad];
    WHC_StackView * stackView = [WHC_StackView new];
    [self.view addSubview: stackView];

    /// 一行代码添加约束
    stackView.whc_LeftSpace(10)
             .whc_TopSpace(10)
             .whc_RightSpace(10)
             .whc_Height(100);

    /// 配置StackView
    stackView.whc_Edge = UIEdgeInsetsMake(10, 10, 10, 10); // 内边距
    stackView.whc_Orientation = Vertical;                  // 自动垂直布局
    stackView.whc_HSpace = 10;                             // 子视图横向间隙
    stackView.whc_VSpace = 10;                             // 子视图垂直间隙

    /// 向StackView中添加子视图
    UIView * view1 = [UIView new];
    UIView * view2 = [UIView new];
    UIView * view3 = [UIView new];
    UIView * view4 = [UIView new];

    [stackView addSubview:view1];
    [stackView addSubview:view2];
    [stackView addSubview:view3];
    [stackView addSubview:view4];

    /// 开始进行布局
    [stackView whc_StartLayout];
}

Swift版WHC_StackView使用范例

override func viewDidLoad() {
    super.viewDidLoad()
    let stackView = WHC_StackView()
    self.view.addSubview(stackView)

    /// 一行代码添加约束
    stackView.whc_Left(10)
             .whc_Top(10)
             .whc_Right(10)
             .whc_Height(100)

    /// 配置StackView
    stackView.whc_Edge = UIEdgeInsetsMake(10, 10, 10, 10)  // 内边距
    stackView.whc_Orientation = .All                       // 自动横向垂直布局
    stackView.whc_HSpace = 10                              // 子视图横向间隙
    stackView.whc_VSpace = 10                              // 子视图垂直间隙

    /// 向StackView中添加子视图
    let view1 = UIView()
    let view2 = UIView()
    let view3 = UIView()
    let view4 = UIView()

    stackView.addSubview(view1)
    stackView.addSubview(view2)
    stackView.addSubview(view3)
    stackView.addSubview(view4)

    /// 开始进行布局
    stackView.whc_StartLayout()
}

部分WHC_AutoLayoutKit demo展示

image

期待

  • 如果您在使用过程中有任何问题,欢迎issue me! 很乐意为您解答任何相关问题!
  • 与其给我点star,不如向我狠狠地抛来一个BUG!
  • 如果您想要更多的接口来自定义或者建议/意见,欢迎issue me!我会全力满足大家!

Licenses

All source code is licensed under the MIT License.