【发布时间】:2014-03-25 15:00:33
【问题描述】:
我正在尝试向 UIScrollView 添加标签。我正在添加一个顶部约束和一个前导约束。 标签没有出现。
这是我的代码。
self.label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
self.label.translatesAutoresizingMaskIntoConstraints = NO;
self.label.backgroundColor = [UIColor clearColor];
self.label.textAlignment = NSTextAlignmentCenter;
self.label.textColor=[UIColor whiteColor];
self.label.text = @"Hello";
[self.imageCarouselScrollView addSubview:self.label];
[self bringSubviewToFront:self.label];
self.titleLabelTopConstraint = [NSLayoutConstraint
constraintWithItem:self
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.imageCarouselScrollView
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:20];
NSLayoutConstraint *titleLeadingConstraint = [NSLayoutConstraint
constraintWithItem:self
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:self.imageCarouselScrollView
attribute:NSLayoutAttributeTrailing
multiplier:1.0
constant:20];
[self addConstraints:@[self.titleLabelTopConstraint,titleLeadingConstraint]];
【问题讨论】:
-
您是否尝试查看
UILabel是否在未添加约束的情况下显示?而且,不要搞笑..您的视图背景颜色没有设置为白色是吗?
标签: ios uiscrollview uilabel autolayout nslayoutconstraint