我正在使用约束添加 scrollView
,它工作正常。但它表现出奇怪的行为。
当我将 scrollView
的框架添加为 [SBV setFrame:CGRectMake(0, 0, scrllView.frame.size.width,1000)];
然后它的颜色总是clearColor
,不管我给它什么。
代码:
UIScrollView *scrllView=[UIScrollView new];
[scrllView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.view addSubview:scrllView];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:scrllView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:scrllView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:scrllView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:scrllView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
[scrllView setContentSize:CGSizeMake(self.view.frame.size.width, 1000)];
UIView *SBV=[UIView new];
[SBV setTranslatesAutoresizingMaskIntoConstraints:YES];
[SBV setFrame:CGRectMake(0, 0, scrllView.frame.size.width,1000)];
[SBV setBackgroundColor:[UIColor grayColor]];
[scrllView addSubview:SBV];
当我将 view
的框架添加为 [SBV setFrame:CGRectMake(0, 0,self.view.frame.size.width,1000)];
然后它的颜色和给我的一样。在这种情况下为灰色
最佳答案
不要使用 CGRectMake 函数,而是保持大小不变。它不会表现出任何奇怪的行为。
关于ios - 当我使用自动布局时,作为 scrollView 的 subview 的 View 颜色没有出现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32493489/