Giter Club home page Giter Club logo

Comments (3)

cloudkite avatar cloudkite commented on July 3, 2024

Priorities don't work well with UILabel. If you set the priority to lower than UILayoutPriorityRequired, I believe Auto Layout will use the label's intrinsicSize instead of the low priority constraint you have created. Which will stretch the width of the label to match the label's content. Thanks

from masonry.

dexcell avatar dexcell commented on July 3, 2024

Okay here is the common problem i would like to solve using masonry

As you can see in the screen shot the nameLabel exceed the discountLabel
screen shot 2013-11-04 at 12

I want the discountLabel has a more "priority" than the nameLabel, so in case the nameLabel has a very long string text, it would just trimmed at the left of discountLabel.

Here is the current constraint code i created with Masonry,

[self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
    make.left.equalTo(self.contentView.left).offset(10);
    make.top.equalTo(self.contentView.top).offset(10);
    make.right.equalTo(self.discountLabel.left).offset(-10).priorityLow();
}];

[self.discountLabel makeConstraints:^(MASConstraintMaker *make) {
    make.centerY.equalTo(self.nameLabel.centerY);
    make.right.equalTo(self.contentView.right).offset(-10).priorityHigh();
}];

Please help
Thank you

from masonry.

cloudkite avatar cloudkite commented on July 3, 2024

You shouldn't need to apply priorities in this case. It doesn't look like you have any constraints that will conflict with each other. Also as explained before Priorities don't work well with UILabels

To get the layout you are after you will need to calculate the preferredMaxLayoutWidth manually.

I just updated the example code to match your use case: https://github.com/cloudkite/Masonry/blob/master/MasonryExamples/Masonry%20iOS%20Examples/MASExampleLabelView.m

also set self.longLabel.numberOfLines = 1;

Hope that helps :)

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.