Skip to content
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

Open
didebbo opened this issue Sep 10, 2024 · 2 comments
Open

Unintended CenterY #171

didebbo opened this issue Sep 10, 2024 · 2 comments

Comments

@didebbo
Copy link

didebbo commented Sep 10, 2024

Screenshot of code
Screenshot of view debug

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).

@s4cha
Copy link
Member

s4cha commented Sep 12, 2024

Hi @didebbo, could you please provide the entire layout code reproducing the issue please ? (including views creating & hierarchy).

@s4cha
Copy link
Member

s4cha commented Sep 12, 2024

@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.
If you want to provide the exact layout desired, I can help you with it. In the meantime, here is a rough implementation.

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
    }
}

Simulator Screenshot - iPhone 15 Pro - 2024-09-12 at 08 00 34

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

No branches or pull requests

2 participants