D2LayoutHelperPod 0.8.3

D2LayoutHelperPod 0.8.3

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最新版本2017年10月

DeceptionAlertViews 维护。



  • 作者
  • Brian Bowman

升级以支持 iOS 7 -> iOS 11

- (UILayoutGuide *)layoutMarginsGuide {
    if (@available(iOS 11.0, *)) {
        return self.safeAreaLayoutGuide;
    } else {
        return self.layoutMarginsGuide;
    }
}

示例

要运行示例项目,请克隆仓库,并在 Example 目录中首先运行 pod install

信息

D2LayoutHelperPod 包含辅助自动布局函数,可以帮助您轻松实现自动布局 :-)
有几个辅助库可能会帮助您简化一些事情。祝您使用愉快!

安装

D2LayoutHelperPod 可通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile
中即可

pod "D2LayoutHelperPod"

从示例

- (void)viewDidLoad {
    [super viewDidLoad];
    // set a view to match the superview
    UIView *green = [UIView new];
    green.backgroundColor = [UIColor greenColor];
    
//    [D20LayoutHelper widthHeightEquivalentsConstraintsWithSuperView:self.view subview:green];
    [green widthHeightEquivalentsConstraintsWithSuperView:self.view];
    [self addTopBar];
}
    
- (void)addTopBar {
    UIView *topView = [UIView new];
    topView.backgroundColor = [UIColor blackColor];
    
    UILabel *navTitle = [UILabel new];
    navTitle.text = @"navigation title here";
    navTitle.textColor = [UIColor blueColor];
    [navTitle sizeToFit];
    
//    [D20LayoutHelper pinItemtoCenterOfSuperView:topView subview:navTitle];
    [navTitle pinItemtoCenterOfSuperView:topView];
//    [D20LayoutHelper pinItemToTopWithSuperView:self.view subview:topView height:60];
    [topView pinItemToTopByLayoutMarginsGuideWithSuperView:self.view height:60];
    
    UIView *marginHighBar = [UIView new];
    marginHighBar.backgroundColor = [UIColor yellowColor];
    
//    [D20LayoutHelper pinItemToTopByLayoutMarginsGuideWithSuperView:topView subview:marginHighBar height:8];
    [marginHighBar pinItemToTopByLayoutMarginsGuideWithSuperView:topView height:8];
    UIView *marginLowBar = [UIView new];
    marginLowBar.backgroundColor = [UIColor yellowColor];
    
//    [D20LayoutHelper pinItemToBottomByLayoutMarginsGuideWithSuperView:topView subview:marginLowBar height:8];
    [marginLowBar pinItemToBottomByLayoutMarginsGuideWithSuperView:topView height:8];
    
    UIView *bottomView = [UIView new];
    bottomView.backgroundColor = [UIColor purpleColor];
    
    UILabel *lowerNavTitle = [UILabel new];
    lowerNavTitle.text = @"add buttons/views/anything here";
    lowerNavTitle.textColor = [UIColor cyanColor];
    [lowerNavTitle sizeToFit];
    
//    [D20LayoutHelper pinItemtoCenterOfSuperView:bottomView subview:navTitle];
    [lowerNavTitle pinItemtoCenterOfSuperView:bottomView];
//    [D20LayoutHelper pinItemToBottomWithSuperView:self.view subview:bottomView height:60];
    [bottomView pinItemToBottomWithSuperView:self.view height:60];
    
    // evenly display some labels vertically
    NSArray<UIView *> *views = [NSArray new];
    
    for (int i = 0;  i < 8; i++) {
        UILabel *someLabel = [UILabel new];
        someLabel.text = [NSString stringWithFormat:@"label #%d", i+1];
        someLabel.backgroundColor = [UIColor magentaColor];
        [someLabel sizeToFit];
        views = [views arrayByAddingObject:someLabel];
    }
    
    //add some labels
    UIView *container = [UIView new];
    [container fillViewBetween:topView bottomView:bottomView superview:self.view topPadding:0 bottomPadding:0];
    
//    [D20LayoutHelper centeredItemsByLayoutMarginsGuideWithSuperView:self.view
//                                                           subviews:views
//                                                          alignment:UIStackViewAlignmentFill
//                                                       distribution:UIStackViewDistributionFillEqually
//                                                               axis:UILayoutConstraintAxisVertical
//                                                            spacing:23];
    
    [UIView evenConstraintsByLayoutMarginsGuideWithSuperView:container
                                                    subviews:views
                                                   alignment:UIStackViewAlignmentFill
                                                distribution:UIStackViewDistributionFillEqually
                                                        axis:UILayoutConstraintAxisVertical
                                                     spacing:23];
    
    [self addMoreLabels];
}

- (void)addMoreLabels {
    // evenly display some boxes horizontally
    NSArray<UIView *> *views = [NSArray new];
    NSArray<UIColor *> *colors = @[
                                   [UIColor purpleColor],
                                   [UIColor orangeColor],
                                   [UIColor cyanColor],
                                   [UIColor yellowColor],
                                   [UIColor redColor]
                                   ];
    
    for (int i = 0;  i < 5; i++) {
        UILabel *someLabel = [UILabel new];
        someLabel.text = [NSString stringWithFormat:@"label #%d", i+1];
        someLabel.backgroundColor = colors[i];
        [someLabel sizeToFit];
        views = [views arrayByAddingObject:someLabel];
    }
    
//    [D20LayoutHelper evenConstraintsByLayoutMarginsGuideWithSuperView:self.view
//                                         subviews:views
//                                        alignment:UIStackViewAlignmentCenter
//                                     distribution:UIStackViewDistributionFillEqually
//                                             axis:UILayoutConstraintAxisHorizontal
//                                          spacing:0];
    [UIView evenConstraintsByLayoutMarginsGuideWithSuperView:self.view
                                                    subviews:views
                                                   alignment:UIStackViewAlignmentCenter
                                                distribution:UIStackViewDistributionFillEqually
                                                        axis:UILayoutConstraintAxisHorizontal
                                                     spacing:0];
}

生成
ScreenShot
ScreenShot

作者

Brian Bowman,[email protected]

许可证

D2LayoutHelperPod 采用 MIT 许可协议。有关更多信息,请参阅 LICENSE 文件。