我有这种特殊的行为UILabel
。任何numberOfLines
工作都可以,除了 1。如果我将行数设置为 1,它会忽略我稍后设置的宽度。我不明白为什么1行搞砸了...
这是我的代码
UILabel *label = [[UILabel alloc] init]; label.backgroundColor = [UIColor greenColor]; label.text = @"here is my label with lots of text to fill, here is my label with lots of text to fill"; label.frame = CGRectMake(20, 20, 100, 0); CGRect rect = label.frame; label.numberOfLines = 2; label.lineBreakMode = NSLineBreakByTruncatingTail; [self.view addSubview:label]; rect.size.width = 100; label.frame = rect; [label sizeToFit];