में ऑटोलायआउट बाधाओं का पालन नहीं करते हैं, मैं UIScrollView
पर एक UIView जोड़ रहा हूं और इसे कुछ मार्जिन को छोड़कर क्षैतिज स्थान भरता हूं। मेरे दृश्य बाधा इस तरह दिखता है:UIView UIScrollView
@"|-16-[theLineView]-16-|"
मैं तो यह एक पंक्ति के रूप में दिखाई देगा एक दृश्य पिक्सेल उच्च बना दिया है, और दो पाठ लेबल के बीच रख दिया:
@"V:[someOtherStuff]-[aTextLabel]-[theLineView]-[anotherLabel]"
हालांकि, मैं लग रहा है कि रेखा की चौड़ाई केवल ऊपर/नीचे के सबसे लंबे लेबल की चौड़ाई तक फैली हुई है।
यह क्यों होगा?
पी.एस मैं इस http://developer.apple.com/library/ios/#technotes/tn2154/_index.html
कोड
पढ़ा है यहाँ एक परीक्षण परियोजना है कि आईपैड सिम पर इस समस्या का दर्शाती से देखने नियंत्रक कोड की सम्पूर्णता है।
- (void)viewDidLoad
{ [सुपर व्यूडिडलोड];
self.scrollView = [[UIScrollView alloc] init];
self.scrollView.translatesAutoresizingMaskIntoConstraints = NO;
self.scrollView.backgroundColor = [UIColor greenColor];
[self.view addSubview:self.scrollView];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[scrollView]|"
options:0
metrics:0
views:@{@"scrollView":self.scrollView}]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[scrollView]|"
options:0
metrics:0
views:@{@"scrollView":self.scrollView}]];
self.line1 = [[UIView alloc] init];
self.line2 = [[UIView alloc] init];
self.label1 = [[UILabel alloc] init];
self.label2 = [[UILabel alloc] init];
self.label3 = [[UILabel alloc] init];
for (UILabel *label in @[self.label1, self.label2, self.label3])
{
label.text = @"I am a label and I am long enough that I can be multiline on an iphone but single on ipad";
}
for (UIView *view in @[self.line1, self.line2, self.label1, self.label2, self.label3])
{
view.translatesAutoresizingMaskIntoConstraints = NO;
view.backgroundColor = [UIColor redColor];
[self.scrollView addSubview:view];
}
//horizontal layout - all views/labels should fill the horizontal space expect for margin
for (UIView *view in @[self.line1, self.line2, self.label1, self.label2, self.label3])
{
NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|-16-[view]-16-|"
options:0
metrics:0
views:@{@"view":view}];
[self.scrollView addConstraints:constraints];
}
//vertical layout - stack em up
[self.scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[lab1]-[line1(==1)]-[lab2]-[line2(==1)]-[lab3]-|"
options:0
metrics:0
views:@{@"lab1":self.label1, @"line1":self.line1, @"lab2":self.label2, @"line2":self.line2, @"lab3":self.label3}]];
}
क्या आपके 1px 'UIView' पर कोई अन्य बाधा है? – Yazid
[देखें] वही दृश्य [theLineView] के रूप में है? क्या आपके पास विकल्प पैरामीटर में कोई संरेखण विकल्प सेटअप है? – rdelmar
विकल्प पैरामीटर में कोई अन्य बाधा या कुछ भी नहीं। मैं देखूंगा कि क्या मैं एक परीक्षण परियोजना में पुन: पेश कर सकता हूं। हां वे विचार समान हैं, स्निपेट को सही किया गया है। –