在iOS6上的UITextView上使用attributText(NSAttributedString)只能使用段落样式或字体,但不能同时使用 [英] Using attributedText (NSAttributedString) on a UITextView on iOS6 only works with paragraph style or font but not both

查看:344
本文介绍了在iOS6上的UITextView上使用attributText(NSAttributedString)只能使用段落样式或字体,但不能同时使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图使用属性UITextView的属性添加可调整的行高我的自定义UITextView。我的代码在模拟器中正常工作,但我无法使其在iPhone5上工作。如果我删除字体行,行高工作,但它的文本恢复为默认较小的字体。如果我添加字体,字体工作,但段落样式被忽略。我试着在一个新鲜的应用程序的vanilla UITextView的代码具有相同的行为,这让我认为这是一个iOS6的错误。有没有人有更好的运气?



我也尝试过各种UITextView替换添加行高度功能,但到目前为止还没有成功。



我的代码如下所示:

  ... 
NSMutableParagraphStyle * paragraphStyle = [NSMutableParagraphStyle alloc] init];
paragraphStyle.minimumLineHeight = lineHeight;
paragraphStyle.maximumLineHeight = lineHeight;

NSString * text = self.text;
NSMutableAttributedString * attributingString = [[NSMutableAttributedString alloc] initWithString:text];

[attributString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0,text.length)];
[attributString addAttribute:NSFontAttributeName value:self.font range:NSMakeRange(0,text.length)];

self.attributedText = attributString;感谢任何人的任何确认或建议!


h2_lin>解决方案

我认为这确实是一个错误。我在过去几天一直在努力,没有找到任何合理的解释。



此外,如果你使用IB来设置你的UITextView,的那些属性将不会被设置为它应该的。



无论如何,我刚刚提交了一个错误。 http://openradar.appspot.com/radar?id=2278401



Matt


I have been trying to use the attributedText property of UITextView to add adjustable line height to my custom UITextView. My code works fine in the simulator, but I am unable to make it work on an iPhone5. If I remove the font line the line height works but it the text reverts to a default smaller font. If I add the font, the font works but the paragraph styling is ignored. I have tried the code on a vanilla UITextView in a fresh app with the same behavior, which makes me think this is an iOS6 bug. Has anyone had any better luck?

I have also tried various UITextView replacements to add line height functionality, but nothing has worked out so far.

My code looks like this:

...
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.minimumLineHeight = lineHeight;
paragraphStyle.maximumLineHeight = lineHeight;

NSString *text = self.text;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];

[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, text.length)];
[attributedString addAttribute:NSFontAttributeName value:self.font range:NSMakeRange(0, text.length)];

self.attributedText = attributedString;

Thanks for any confirmation or suggestions anyone has!

解决方案

I think this is indeed a bug. I've been struggling with it for the past few days and couldn't find any reasonable explanation.

Also, if you use IB to set up your UITextView, a few of those attributes won't be set as it should.

Anyway, I just filed a bug on that. http://openradar.appspot.com/radar?id=2278401

Matt

这篇关于在iOS6上的UITextView上使用attributText(NSAttributedString)只能使用段落样式或字体,但不能同时使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆