Skip to content

Why is the subview constraint incorrect? #193

Closed
@shmilyQin

Description

@shmilyQin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions