我在UILabel工作。但setLineBreakMode已被弃用。我一直在使用NSAttributedString。但UILabel setLineBreakMode追求的是UILabel setNumberOfLines,否则就不能工作。
之前:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(42.0f, 10.0f, 275.0f, 50.0f)];
label.text = @"XXXXXX";
memoLabel.textAlignment = UITextAlignmentLeft;
memoLabel.numberOfLines = 2;
memoLabel.lineBreakMode = UILineBreakModeTailTruncation;
memoLabel.font = [UIFont systemFontOfSize:11];
memoLabel.backgroundColor = [UIColor clearColor];IOS 6之后:
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
paragraphStyle.alignment = NSTextAlignmentLeft;
NSAttributedString *string
= [[NSAttributedString alloc] initWithString:text
attributes:[NSDictionary
dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:11],
NSFontAttributeName,
paragraphStyle, NSParagraphStyleAttributeName,nil]];
[paragraphStyle release];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(42.0f, 10.0f, 275.0f, 50.0f)];
label.attributedText = string;
[string relase];我想在展示之前和之后是一样的。如何显示多行?
发布于 2012-11-03 15:26:27
iOS 6中不推荐使用lineBreakMode属性。它只是更改了常量的名称。旧常量已弃用,但仍可用。即使要部署到较旧的iOS,也可以使用新的常量,因为常量只是枚举值。旧名称和新名称具有相同的值。所以,只需设置memoLabel.lineBreakMode = NSLineBreakByTruncatingTail即可。
您的示例代码似乎没有利用任何特定于属性字符串的特性。如果你不需要带属性的字符串,只要继续使用普通字符串即可。这在iOS 6中仍然有效。
发布于 2012-12-31 04:40:31
使用NSLineBreakByTruncatingTail而不是UILineBreakModeTailTruncation
https://stackoverflow.com/questions/13206657
复制相似问题