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

Posted

技术标签:

【中文标题】如何在 iCarousel 的 cellview 中居中元素?【英文标题】:How to center elements in cellview in iCarousel? 【发布时间】:2014-01-27 20:46:13 【问题描述】:

我想在 iCarousel 视图中居中放置三个 UI 元素(一个按钮和两个文本标签)。我试过像这样使用 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】:

试试这个:

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

这应该做的工作

【讨论】:

以上是关于如何在 iCarousel 的 cellview 中居中元素?的主要内容,如果未能解决你的问题,请参考以下文章