在tableview中使用FlexLayout为代码表视图单元格添加了垂直约束到flex容器
tagsView.willRemoveSubview(rootFlexContainer)
tagsView.addSubview(rootFlexContainer)
rootFlexContainer.flex.direction(.rowReverse).wrap(.wrap).alignSelf(.stretch).justifyContent(.start).paddingRight(5).define { (flex) in
for i in 0..<(array.count > 3 ? 3 : array.count) {
let nameLabel = TagLabel()
//nameLabel.lineBreakMode = .byCharWrapping
nameLabel.font = FontStyle.ProximaNovaRegular(size: 12)
nameLabel.layer.borderColor = UIColor.hexStringToUIColor(hex: TravelXStrings.grayBorderColor).cgColor
nameLabel.layer.cornerRadius = 5
nameLabel.layer.borderWidth = 1.0
nameLabel.textColor = .black
nameLabel.text = " "+array[i]+" "
//nameLabel.sizeToFit()
flex.addItem(nameLabel).margin(2)
}
tagsView.flex.layout(mode: .fitContainer)
}
override func layoutSubviews() {
super.layoutSubviews()
layout()
}
fileprivate func layout() {
tagsView.flex.layout(mode: .fitContainer)
//tagsView.flex.layout(mode: .adjustWidth)
}
这是屏幕截图