注意:当iOS 7处于NDA下时,我在开发者论坛上询问了这一点.我在这里发布,因为我找到一个解决方案,并认为其他人可能会发现它有用.
解决方法 我找到了一个解决方案.处理通知时,您需要处理属性并查找文本样式并更新字体:- (voID)preferredContentSizeChanged:(NSNotification *)aNotification{ UITextVIEw *textVIEw = <the text vIEw holding your attributed text> NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:textVIEw.attributedText]; NSRange range = NSMakeRange(0,attributedString.length - 1); // Walk the string's attributes [attributedString enumerateAttributesInRange:range options:NSAttributedStringEnumerationReverse usingBlock: ^(NSDictionary *attributes,NSRange range,BOol *stop) { // Find the Font descriptor which is based on the old Font size change NSMutableDictionary *mutableAttributes = [NSMutableDictionary dictionaryWithDictionary:attributes]; UIFont *Font = mutableAttributes[@"NSFont"]; UIFontDescriptor *FontDescriptor = Font.FontDescriptor; // Get the text style and get a new Font descriptor based on the style and update Font size ID styleAttribute = [FontDescriptor objectForKey:UIFontDescriptorTextStyleAttribute]; UIFontDescriptor *newFontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:styleAttribute]; // Get the new Font from the new Font descriptor and update the Font attribute over the range UIFont *newFont = [UIFont FontWithDescriptor:newFontDescriptor size:0.0]; [attributedString addAttribute:NSFontAttributename value:newFont range:range]; }]; textVIEw.attributedText = attributedString;}总结
以上是内存溢出为你收集整理的ios7 – 在UITextView中处理NSAttributedString的UIContentSizeCategoryDidChangeNotification全部内容,希望文章能够帮你解决ios7 – 在UITextView中处理NSAttributedString的UIContentSizeCategoryDidChangeNotification所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)