Add the weight of each view to the AutoLayout

Source: Internet
Author: User

The weight of each view is added to the AutoLayout so that the relationship between them is clearer, such as:

DoubleIconviewweight =1; DoubleTitlelabelweight = A; DoubleTimelabelweight =3;     DoubleStandardweigth =Iconviewweight; DoubleIconviewweightratio = iconviewweight/standardweigth; DoubleTitilelabelwightratio = titlelabelweight/standardweigth; DoubleTimelabelwightratio = timelabelweight/standardweigth; UIView*standardview =_iconview;nsdictionary*views =nsdictionaryofvariablebindings (_iconview, _titilelabel, _timelabel, Bgimageview);Nslayoutconstraint *constraint =[Nslayoutconstraint constraintwithitem:_iconview att Ribute:nslayoutattributewidth Relatedby:nslayoutrelatione                                                                  Qual Toitem:standardview                                                                 Attribute:nslayoutattributewidth MULTIPLIER:ICONVIEWWEIGHTRATIO constant:0.0f];        [Self addconstraint:constraint]; Constraint=[Nslayoutconstraint Constraintwithitem:_titilelabel Attribute:nslayoutat                                                 Tributewidth relatedby:nslayoutrelationequal                                             Toitem:standardview Attribute:nslayoutattributewidth Multiplier:titilelabelwightratio Constan T:0.0f];    [Self addconstraint:constraint]; Constraint=[Nslayoutconstraint Constraintwithitem:_timelabel attribute:nslayoutattr                                                 Ibutewidth relatedby:nslayoutrelationequal                                             Toitem:standardview Attribute:nslayoutattributewidth Multiplier:timelabelwightratio constant:
    0.0f];        [Self addconstraint:constraint]; Constraints= [Nslayoutconstraint Constraintswithvisualformat:@"|-[_iconview]-[_titilelabel]-[_timelabel]-|"Options:nslayoutformatalignallcentery    Metrics:nil Views:views];    [Self addconstraints:constraints]; Constraint=[Nslayoutconstraint Constraintwithitem:_iconview Attribute:nslayoutattri                                                 Butecentery relatedby:nslayoutrelationequal                                             ToItem:self.contentView Attribute:nslayoutattributecentery Multiplier:1.0constant:0.0f]; [Self addconstraint:constraint];

The code is more brief, but this applies to some specific situations

Add the weight of each view to the AutoLayout

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.