如何解决ios swift flexlayout 添加项目后获取 flex 的高度
以下是我在 flex 布局中添加项目的代码 https://github.com/layoutBox/FlexLayout
rootFlexContainer.flex.direction(.row).wrap(.wrap).alignSelf(.auto).justifyContent(.start).paddingRight(2).define { (flex) in
for i in 0..<((retailerTags?.count ?? 0) > 3 ? 3 : (retailerTags?.count ?? 0)) {
let nameLabel = UIButton()
nameLabel.isUserInteractionEnabled = false
nameLabel.setTitle((retailerTags?[i] ?? "").trim(),for: .normal)
nameLabel.setTitleColor(.black,for: .normal)
nameLabel.titleLabel?.font = FontStyle.ProximaNovaRegular(size: 11)
nameLabel.contentEdgeInsets = UIEdgeInsets(top: 1.5,left: 4,bottom: 1.5,right:4)
nameLabel.layer.borderColor = UIColor.hexStringToUIColor(hex: TravelXStrings.grayBorderColor).cgColor
nameLabel.layer.cornerRadius = 8
nameLabel.layer.borderWidth = 1.0
flex.addItem(nameLabel).margin(2)
}
if cashbackString != "" {
let cashbackLabel = UIButton()
cashbackLabel.backgroundColor = UIColor.hexStringToUIColor(hex: TravelXStrings.orangeCashbackColor)
cashbackLabel.isUserInteractionEnabled = false
cashbackLabel.setTitle(cashbackString,for: .normal)
cashbackLabel.setTitleColor(.black,for: .normal)
cashbackLabel.titleLabel?.font = FontStyle.ProximaNovaRegular(size: 10)
cashbackLabel.contentEdgeInsets = UIEdgeInsets(top: 1.5,left: 5,right: 5)
cashbackLabel.layer.cornerRadius = 8
cashbackLabel.layer.borderWidth = 0
flex.addItem(cashbackLabel).margin(2)
}
}
添加视图后,在尝试使用 bounds.height,flex.intrinsicSize.height 添加元素后不久,我无法获得此 rootflex 容器的高度,但高度返回错误,在方法 layoutSubviews 中获取精确高度() 只
override func layoutSubviews() {
super.layoutSubviews()
layout()
}
fileprivate func layout() {
rootFlexContainer.frame.size.width = frame.width - 20
rootFlexContainer.flex.layout(mode: .adjustHeight)
if(rootFlexContainer.frame.height ! = 0){
tagsHeight.constant = rootFlexContainer.frame.height
}
//tagsView.flex.layout(mode: .adjustWidth)
}
如何在 layoutSubviews 被调用之前以及在添加元素之后不久获得精确的 flex 布局高度?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。