HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios7 – 在UITextView中处理NSAttributedString的UIContentSizeCategoryDidChangeNotification大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在UITextView中有一个NSAttributedString,并且在处理动态类型,特别是文本样式时,希望处理UIContentSizeCategoryDidChangeNotification.我所看到的所有例子(IntroToTextKitDemo)解决了整个UI元素的字体是一样的.有没有人知道如何正确处理这些所有属性更新正确?

注意:当iOS 7处于NDA下时,我在开发者论坛上询问了这一点.我在这里发布,因为我找一个解决方案,并认为其他人@R_754_@R_673_10098@@它有用.

解决方法

我找到了一个解决方案.处理通知时,您需要处理属性并查找文本样式并更新字体: @H_607_8@- (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所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。