NSLineBreakByTruncatingTail没有得到反映

时间:2016-02-22 13:38:11

标签: iphone uitableview uilabel

嗨我有一个UILabel作为表视图单元格的子视图添加。我希望在一行中有一个带有点的长文本。但是如果我将numberOfLines设为1,那么标签宽度不能是组。标签尝试在1行中显示整个文本并离开单元格。如果我将numberOfLines设置为0,并将lineBreakMode设置为NSLineBreakByTruncatingTail,那么文本将分为两行。我在下面添加了一段代码,。

self.titleTextField = [[UILabel alloc] init];
 [self.titleTextField setFrame:CGRectMake(45, 33, self.arrowMark.frame.origin.x-self.titleTextField.frame.origin.x, self.titleTextField.frame.size.height)];
        //newly added_jacket

        self.titleTextField.numberOfLines =0;
        self.titleTextField.lineBreakMode = NSLineBreakByTruncatingTail;
        self.titleTextField.textColor =[UIColor colorWithRed:30.0f/255.0f green:164.0f/255.0f blue:220.0f/255.0f alpha:1.0];
        [self.titleTextField setUserInteractionEnabled:NO];
        [self.titleTextField setBackgroundColor:[UIColor clearColor]];


        [self.cellBGImage addSubview:self.titleTextField];
        [self.titleTextField sizeToFit];

皮斯帮助我。

1 个答案:

答案 0 :(得分:0)

只需删除 [self.titleTextField sizeToFit]; 此行和NSLineBreakByTruncatingTail将完成。