-
-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unintended CenterY #171
Comments
Hi @didebbo, could you please provide the entire layout code reproducing the issue please ? (including views creating & hierarchy). |
@didebbo, this is the default behavior indeed, when using multiple horizontal views in a layout block, they are aligned horizontally. One catch here is that the top and bottom constraints are only applied to the first view of the horizontal layout, here box1. In your case, you might be better off using other apis. Here is an example below. import UIKit
import Stevia
class View: UIView {
let box1 = UITextView()
let box2 = UITextView()
convenience init() {
self.init(frame: CGRect.zero)
// 1 - Hierarcy
subviews {
box1
box2
}
// 2 - Layout
box1.top(10).bottom(0)
|-10-box1.width(>=100)-box2-10-|
// Provide default height when box is empty
box2.height(>=100)
// Match box 1 top
box2.Top == box1.Top
// Match box1 width
box2.Width == box1.Width
// Stop growing at the bottom of the screen
box2.Bottom <= 10
// 3 -Style
box1.style { v in
v.backgroundColor = .red
}
box2.style { v in
v.backgroundColor = .blue
// Fit content and grow with it
v.isScrollEnabled = false
}
}
}
class ViewController: UIViewController {
let v = View()
override func viewDidLoad() {
super.viewDidLoad()
v.box1.text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
v.box2.text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
}
override func loadView() {
self.view = v
}
}
|
As you can see, without explicitly specifying the CenterY constraint, it is still being applied to the subviews, causing this unintended centralized effect.
Using the layout: align(tops: |-10--boxOne--10--boxTwo--10-|),
boxTwo gets stretched and no longer takes its height based on its content.
It would be ideal to have additional layout options such as anchorTo(.top | .bottom | .leading | .trailing).
The text was updated successfully, but these errors were encountered: