यदि आप एसी के एट्रिब्यूट सेंटररएक्स को अपने पर्यवेक्षक के एट्रिब्यूट सेंटर, एक्सट्रिब्यूटिंग, या एट्रिब्यूट ट्रायलिंग से संबंधित करते हैं, तो आप गुणक और बाधा का उपयोग करके अपनी वांछित बाधा व्यक्त करने में सक्षम होना चाहिए। ध्यान रखें कि निरंतर मूल्यांकन किया जाता है जब बाधा उत्पन्न होती है, और आपका उदाहरण स्थिरांक AC.superview की चौड़ाई में परिवर्तन के रूप में अपडेट नहीं होगा।
यदि आप शब्दों में व्यक्त कर सकते हैं कि आप अपने पर्यवेक्षण के सापेक्ष एसी कैसे चाहते हैं, तो हम एक बाधा का सुझाव दे सकते हैं।
संपादित
यहाँ 5 NSButtons साथ एक उदाहरण है। वे स्वयं और उनके बीच की जगह का विस्तार होता है ताकि रिक्त स्थान बटन के रूप में 30% चौड़े हों, सभी बटनों की समान चौड़ाई होती है, और सभी रिक्त स्थानों की समान चौड़ाई होती है। केवल अंतर के लिए 4 अदृश्य NSViews बनाना बहुत बोझिल है, विशेष रूप से यह समझते हुए कि आप इसे ऑटोलायआउट के बाहर काम कर चुके हैं। लेकिन मामले में आप उत्सुक हैं:
// Assuming these NSViews and NSButtons exist,
//NSView* superview ;
//NSButton *buttonOne, *buttonTwo, *buttonThree, *buttonFour, *buttonFive ;
[superView removeConstraints:superView.constraints] ;
// Create empty NSViews to fill the space between the 5 buttons.
NSView* spaceOne = [NSView new] ;
NSView* spaceTwo = [NSView new] ;
NSView* spaceThree = [NSView new] ;
NSView* spaceFour = [NSView new] ;
spaceOne.translatesAutoresizingMaskIntoConstraints = NO ;
spaceTwo.translatesAutoresizingMaskIntoConstraints = NO ;
spaceThree.translatesAutoresizingMaskIntoConstraints = NO ;
spaceFour.translatesAutoresizingMaskIntoConstraints = NO ;
[superView addSubview:spaceOne] ;
[superView addSubview:spaceTwo] ;
[superView addSubview:spaceThree] ;
[superView addSubview:spaceFour] ;
NSDictionary* views = NSDictionaryOfVariableBindings(superView,buttonOne,buttonTwo,buttonThree,buttonFour,buttonFive,spaceOne,spaceTwo,spaceThree,spaceFour) ;
// Vertically align buttonOne to its superview however you like.
[superView addConstraints: [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[buttonOne]" options:0 metrics:nil views:views ] ] ;
// Make the "space" NSViews' widths equal and >= 10. Make the buttons' widths equal.
[superView addConstraints: [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[buttonOne][spaceOne(>=10)][buttonTwo(==buttonOne)][spaceTwo(==spaceOne)][buttonThree(==buttonOne)][spaceThree(==spaceOne)][buttonFour(==buttonOne)][spaceFour(==spaceOne)][buttonFive(==buttonOne)]|" options: NSLayoutFormatAlignAllCenterY metrics:nil views:views ] ] ;
// Make the "space" NSViews' widths 30% of the NSButtons' widths.
[superView addConstraint: [NSLayoutConstraint constraintWithItem: spaceOne
attribute: NSLayoutAttributeWidth
relatedBy: NSLayoutRelationEqual
toItem: buttonOne
attribute: NSLayoutAttributeWidth
multiplier: 0.3
constant: 0 ] ] ;
स्रोत
2012-12-14 14:49:46
वास्तव में अच्छा सवाल है। रहस्यमय लगता है। –