ios - Autolayout with 3 labels equally width -
i need display 3 labels : "|-15-[label1]-0-[label2]-0-[label3]-15|".the label1,label2,label3 should have equal widths.how acthieve using autolayout coding.any suggestion appreciated.
i've tried below,but couldn't see on headerview.
nsdictionary *views2 = nsdictionaryofvariablebindings(label1, label2, label3); [headerview addconstraints:[nslayoutconstraint constraintswithvisualformat:@"h:|-leftpadding-[label1]-0-[label2]-0-[label3]-rightpadding-|" options:0 metrics:@{@"leftpadding":[nsnumber numberwithint:15],@"rightpadding":[nsnumber numberwithint:15]} views:views2]]; [headerview addconstraint:[nslayoutconstraint constraintwithitem:label1 attribute:nslayoutattributewidth relatedby:nslayoutrelationequal toitem:label2 attribute:nslayoutattributewidth multiplier:1 constant:0]]; [headerview addconstraint:[nslayoutconstraint constraintwithitem:label1 attribute:nslayoutattributewidth relatedby:nslayoutrelationequal toitem:label3 attribute:nslayoutattributewidth multiplier:1 constant:0]]; [headerview addconstraint:[nslayoutconstraint constraintwithitem:label2 attribute:nslayoutattributewidth relatedby:nslayoutrelationequal toitem:label3 attribute:nslayoutattributewidth multiplier:1 constant:0]]; [headerview addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:|[label1]|" options:0 metrics:nil views:views2]]; [headerview addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:|[label2]|" options:0 metrics:nil views:views2]]; [headerview addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:|[label3]|" options:0 metrics:nil views:views2]];
if want views have same width irrespective of distance between them. should use concept of spacer views. refer apple documentation more information on spacer views. think spacer best way go this. when have used spacers need apply constraints spacer views cause labels become equal in width.
Comments
Post a Comment