iOS基于UIKit实现的简易弹性盒子布局SNFlexView

2023-03-19  本文已影响0人  迷路的小小

SNFlexView是基于UIKit@resultBuilder实现的简易的弹性盒子布局(仅支持自动布局)。

  1. 用法
let flexView = SNFlexView(lineSpacing: 5, interitemSpacing: 5, contents: {
    for str in contentStr {
        if str.count > 5 {
            UILabel(text: str)
                .textColor(.white)
                .padding(UIEdgeInsets(top: 2, left: 5, bottom: 2, right: 5))
                .backgroundColor(.red)
                .cornerRadius(5)
                .masksToBounds(true)
        }
        else {
            UILabel(text: str)
                .textColor(.white)
                .padding(UIEdgeInsets(top: 2, left: 5, bottom: 2, right: 5))
                .backgroundColor(.blue)
                .cornerRadius(5)
                .masksToBounds(true)
        }
    }
})
@SNViewBuilder
var contents: [UIView] {
    for str in contentStr {
        UILabel(text: str)
            .textColor(.white)
            .padding(UIEdgeInsets(top: 2, left: 5, bottom: 2, right: 5))
            .backgroundColor(.red)
            .cornerRadius(5)
            .masksToBounds(true)
    }
}
let flexView = SNFlexView(lineSpacing: 5, interitemSpacing: 5, contents: contents)
  1. 参数说明
  1. 效果图


    简易弹性盒子
上一篇 下一篇

猜你喜欢

热点阅读