美文网首页
Masonry NSArray 平均排列

Masonry NSArray 平均排列

作者: 阳光下的灰尘 | 来源:发表于2022-09-27 15:06 被阅读0次

NSArray+MASAdditions.h还有两个未提及的方法,此刻可以派上用场了。

/**
 *  distribute with fixed spacing
 *
 *  @param axisType     which axis to distribute items along
 *  @param fixedSpacing 每个item之间的距离
 *  @param leadSpacing  the spacing before the first item and the container
 *  @param tailSpacing  the spacing after the last item and the container
 */
- (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedSpacing:(CGFloat)fixedSpacing leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing;
/**
 *  distribute with fixed item size
 *
 *  @param axisType        which axis to distribute items along
 *  @param fixedItemLength 每个item的长度
 *  @param leadSpacing     the spacing before the first item and the container
 *  @param tailSpacing     the spacing after the last item and the container
 */
- (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedItemLength:(CGFloat)fixedItemLength leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing;

例如 使用方法

  NSArray <UIView *>*views = @[redView,yellowView,greenView];
    [views mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
    }];
    [views mas_distributeViewsAlongAxis:MASAxisTypeHorizontal
                       withFixedSpacing:10
                            leadSpacing:0
                            tailSpacing:0];

相关文章

网友评论

      本文标题:Masonry NSArray 平均排列

      本文链接:https://www.haomeiwen.com/subject/koecartx.html