我正在尝试使用NSAttributed
字符串在UILabel
中显示,并且我使用换行作为换行模式。但当我运行应用程序时,它抛出异常"NSAttributedString invalid for autoresizing, it must have a single spanning paragraph style (or none) with a non-wrapping lineBreakMode.
“
有人能建议我如何解决这个问题吗?
发布于 2013-02-27 15:39:37
我假设你错误地使用了NSMutableAttributedString
,它应该作为under使用,
NSMutableDictionary *a = [[NSMutableDictionary alloc] init];
[a setObject:[NSNumber numberWithInt:1] forKey:NSStrikethroughStyleAttributeName];
NSMutableAttributedString *b = [[NSMutableAttributedString alloc] initWithString:@"abcd" attributes:a];
self.label.attributedText = b;
在尝试上面的代码之后,您应该会得到如我在图中所示的UILabel输出
但是如果你想单独设置属性,你应该这样做
[b addAttribute:ATTRIBUTENAME value:VALUE range:RANGE];
例如,设置背景颜色的属性
[str addAttribute:NSBackgroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(2,4)];
发布于 2013-09-18 17:06:31
要修复此问题,请设置:
[yourLabel setAdjustsFontSizeToFitWidth:NO];
只需确保您不会在以后的代码中覆盖它;)
发布于 2013-06-18 08:57:09
对于任何其他看到这个问题的人。对我有帮助的是禁止调整UILabel
的文本大小。在我的代码中我有:
[myLabel setAdjustsLetterSpacingToFitWidth:YES];
[myLabel setAdjustsFontSizeToFitWidth:YES];
[myLabel setMinimumScaleFactor:15.0/myLabel.font.pointSize];
移除它并开始工作。
https://stackoverflow.com/questions/15115433
复制相似问题