Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Why is the subview constraint incorrect? #193

Open
shmilyQin opened this issue Jan 11, 2022 · 1 comment
Open

Why is the subview constraint incorrect? #193

shmilyQin opened this issue Jan 11, 2022 · 1 comment

Comments

@shmilyQin
Copy link

shmilyQin commented Jan 11, 2022

Thanks for creating a really nice library, but I'm a little confused right now. Constraints not working after using FlexLayout for subviews

class CellsViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
view.flex.define { flex in
flex.addItem(infoView).height(60).marginTop(64)
}
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
view.flex.layout()
}
lazy var infoView: AnimationView = {
let value = AnimationView(frame: .zero)
return value
}()

}

class AnimationView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .green
flex.paddingHorizontal(12)
.alignItems(.center)
.direction(.row)
.define { flex in
flex.addItem(doubleTitileView)
}
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
lazy var doubleTitileView: DoubleTitleView = {
let value = DoubleTitleView(frame: .zero)
return value
}()
override func layoutSubviews() {
super.layoutSubviews()
self.layout()
}
func layout(){
self.flex.layout()
}
}

class DoubleTitleView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
initInterface()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func initInterface() {
self.flex.direction(.column)
.justifyContent(.center)
.define { flex in
flex.addItem(titleLabel)
flex.addItem(subLabel)
}
}
override func layoutSubviews() {
super.layoutSubviews()
self.flex.layout()
}
lazy var titleLabel: UILabel = {
let value = UILabel()
value.font = UIFont.systemFont(ofSize: 16)
value.text = "textOne"
return value
}()
lazy var subLabel: UILabel = {
let value = UILabel()
value.font = UIFont.systemFont(ofSize: 14)
value.text = "textOneTwo"
return value
}()
}

image

The padding and alignItems doesn`t work

@zhuolingzhao007
Copy link

remove the subview 's layoutsubviews() method. I don't know why

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants