我试图根据文本中的文本重新调整大小(或者我允许ie108的最大宽度),并在它旁边放置一个按钮,下面的代码实际上在调试时给出满意的结果,但标签的宽度不是相应地改变。 是否有任何特殊设置可以在xib或其他任何东西中做请帮助Iam。动态调整UILabel的大小,但不起作用。
NSDictionary *[email protected]{NSFontAttributeName:locFeedcell.lbl_location.font};
CGFloat width=[locFeedcell.lbl_location.text sizeWithAttributes:attrib].width;
CGRect newLabelframe=locFeedcell.lbl_location.frame;
CGRect newButtonFrame=locFeedcell.btn_map.frame;
if (width>=108.00f) {
newLabelframe.size.width=108.00;
} else {
newLabelframe.size.width=width;
newButtonFrame.origin.x=locFeedcell.lbl_location.bounds.origin.x+width+4.00;
}
locFeedcell.lbl_location.frame=newLabelframe;
locFeedcell.btn_map.frame=newButtonFrame;
这里是xib文件的快照。
是自动布局已启用,不知道这一点。谢谢,这是一个巨大的帮助。并且还提供了小费。 –