UITableViewCell中的UILabel在Interface Builder中移动时剪辑内容

时间:2012-12-14 12:27:17

标签: objective-c ios uitableview interface-builder

我在最新版本的Xcode中的UITableViewCell中有一个UILabel。我通过一些换行符动态地为其添加文本,并自动调整,然后调整我的表格单元格高度。只要我将UILabel单独留在Interface builder中,一切正常。如果我尝试将其向左或向右移动1个像素,则内容将被剪切为单行文本,并且该行中的每个其他行都不可见。这实际上非常荒谬。我已经尝试了标签的每个设置,但如果我移动它,它会剪切除第一行之外的所有设置。有没有人知道其他任何事情要尝试?我知道这听起来很荒谬。

- (CGFloat)heightForRowInInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation     {
    CGFloat width = (interfaceOrientation == UIInterfaceOrientationPortrait ||         interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) ?    kDescriptionLabelWidthPortrait : kDescriptionLabelWidthLandscape;
    CGFloat height = [[self descriptionString] sizeWithFont:_descriptionLabelFont constrainedToSize:CGSizeMake(width, MAXFLOAT)].height + kDescriptionLabelPadding;
 return MIN(MAX(height, kMinCellHeight), kMaxCellHeight); 

}

#define kDescriptionLabelWidthPortrait 429.0f
#define kDescriptionLabelWidthLandscape 685.0f
#define kDescriptionLabelPadding 50.0f
#define kDescriptionLabelFontName @"Helvetica"
#define kDescriptionLabelFontSize 14.0f
#define kMinCellHeight 44.0f
#define kMaxCellHeight 2009.0f

4 个答案:

答案 0 :(得分:1)

我不确定但是请尝试取消选中使用autoLayout为身份和类型部分中的xib文件。

答案 1 :(得分:1)

尝试将标签的行数设置为0. 0允许标签所需的行数。

答案 2 :(得分:1)

这对您有所帮助,这是CustomCell.m

中的代码
- (void) updateWithComment:(Comment *) comment
{
    self.aComment = comment;

    [self.userBtn setTitle:[NSString stringWithFormat:@"%@ %@",comment.user.firstName,comment.user.lastName] forState:UIControlStateNormal];

    CGSize size =  [aComment.text sizeWithFont:[UIFont fontWithName:@"Helvetica" size:14.0] constrainedToSize:CGSizeMake(210, 999)];

    [self.textLbl setFrame:CGRectMake(textLbl.frame.origin.x, textLbl.frame.origin.y, 225, size.height)];

    [self.textLbl setText:aComment.text];
}

enter image description here

答案 3 :(得分:0)

尝试重新启动XCode和Mac,创建另一个UILabel,然后更改其框架。