Giter Club home page Giter Club logo

Comments (3)

levieggert avatar levieggert commented on July 22, 2024

Hey so I narrowed down what was causing the constraints on my custom toolbar to break. I'm not sure if this is a bug or not, but it ended up coming from constraints I had applied to UILabels.

I'll try my best to explain.

My UIViewController hierarchy looks like below where rootView is the view of my UIViewController. That view has 3 subviews. Navigation Bar, Toolbar, and a Modal. All of these are custom classes I created which have a root view attached to the UIViewController like you see below.

rootView
-> navigation bar (Custom UIView)
-> title(UILabel)
-> toolbar (Custom UIView)
-> button 0 (UIButton)
-> button 1 (UIButton)
-> button 2 (UIButton)
-> button 3 (UIButton)
-> modal(Custom UIView)
-> optionsView (UIView)
-> title(UILabel)

The UILabel titles that are attached to those view's had top, left, right, and height constraints like this which was causing the button width constraints to break on my toolbar when ever I either dismissed a view controller or rotated the device.

make.top.equalTo(self.view.mas_top).with.offset(statusBarHeight);
make.left.equalTo(self.view.mas_left);
make.right.equalTo(self.view.mas_right);
make.height.equalTo([NSNumber numberWithFloat:titleHeight]);

Changing the UILabel constraints to what I have now below has fixed the toolbar constraints from breaking. I'm not entirely sure how this fixed it, but it did. These are the only UILabels I have constraints applied to and I had to change both because it kept breaking the toolbar button constraints.

make.top.equalTo(self.view.mas_top).with.offset(statusBarHeight);
make.centerX.equalTo(self.view.mas_centerX);
make.width.equalTo([NSNumber numberWithFloat:titleWidth]);
make.height.equalTo([NSNumber numberWithFloat:titleHeight]);

from masonry.

cloudkite avatar cloudkite commented on July 22, 2024

Sorry for the late reply, I'm currently traveling and am in and out of wifi. UILabels are a bit of a special case in auto layout. You may need to set preferredMaxLayoutWidth see the labels example.

Also just a tip to make your code a bit more concise. You can do @(titleWidth) instead of [NSNumber numberWithFloat:titleWidth]

from masonry.

levieggert avatar levieggert commented on July 22, 2024

Hey good to know it's definitely UILabels. Thanks for the tip too and great work on Masonry.

from masonry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.