如何在iCarousel的cellview中居中元素?

时间:2014-01-27 20:46:13

标签: ios icarousel

我有三个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]];

但它不起作用。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

试试这个:

[self.backgroundView setCenter:CGPointMake(xcoord, ycoord)]; 

那应该做的工作