ios 6:使用自动布局约束垂直居中UILabel

Jam*_*rpe 5 iphone centering ios autolayout ios6

UILabel有时候想要在一个单元格中垂直居中.这必须以编程方式完成.我已经尝试添加以下约束来居中它(locName是UILabel):

[cell addConstraint:[NSLayoutConstraint constraintWithItem:cell
attribute:NSLayoutAttributeCenterY relatedBy:0 toItem:cell.locName 
attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
Run Code Online (Sandbox Code Playgroud)

这是我得到的结果:

在此输入图像描述

看起来它的中心位置,但也许改变了它的高度UILabel

这是IB中的视图控制器:

在此输入图像描述

如何以编程方式实现垂直居中?

Oma*_*arj 0

尝试在居中后达到 UIlabel 高度???

或者您可以以编程方式重新分配自定义单元格中的标签位置。