我有三个UI元素在一起(一个按钮和两个文本标签),我想在iCarousel的视图中居中。我尝试过像这样使用NSLayoutContraits:
[self.backgroundView addConstraint:[NSLayoutConstraint constraintWithItem:self.descriptionLabel
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.backgroundView
attribute:NSLayoutAttributeCenterX
multiplier:1
constant:0]];
[self.backgroundView addConstraint:[NSLayoutConstraint constraintWithItem:self.descriptionLabel
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self.backgroundView
attribute:NSLayoutAttributeCenterY
multiplier:1
constant:0]];
但它不起作用。有什么想法吗?
答案 0 :(得分:0)
试试这个:
[self.backgroundView setCenter:CGPointMake(xcoord, ycoord)];
那应该做的工作