textkit

How can I set the color and alignment of attributed text in a UITextView in iOS 7?

試著忘記壹切 提交于 2019-12-18 11:41:43
问题 The formatting of my textViews worked fine in iOS 6, but no longer in iOS 7. I understand with Text Kit much of the under the hood stuff has changed. It's become really quite confusing, and I'm hoping someone can help straighten it out a bit by helping me with something as simple as this. My static UITextView originally was assigned a value for it's textColor and textAlignment properties. Then I made a NSMutableAttributedString , assigned it an attributes, then assigned it to the textView's

Adjust letter spacing in iOS 7

你说的曾经没有我的故事 提交于 2019-12-18 10:33:08
问题 In iOS 7, when navigating back using the new swipe-from-edge-of-screen gesture, the title of the Back button ("Artists") fades from being pink (in the example below) and having regular font weight to being black and having bold font weight. It seems to me that the animation uses two different labels in order to achieve this effect; one fading out as the other fades in. However, Apple has somehow adjusted the font so that the regular label perfectly overlays the bold one, thus creating the

How to decide where soft line-breaks occur with TextKit?

烈酒焚心 提交于 2019-12-13 07:57:05
问题 I'm trying to define where soft line breaks occur within my text, and the NSLayoutManagerDelegate method layoutManager(_:shouldBreakLineByWordBeforeCharacterAt:) seems like the place to start. My problem is it's not getting called, although my other methods are. This is occurring with a basic UITextView setup. Under what conditions is this method called - am I looking in the right place? Here's what my TextKit stack looks like: class DemoTextView: UITextView, NSLayoutManagerDelegate { // MARK

NSAttributedString reporting incorrect sizes for UITextView sizeThatFits and boundingRectWithSize with correct options set

╄→гoц情女王★ 提交于 2019-12-12 08:38:04
问题 I have an NSAttributedString that is reporting a boundingRectWithSize (and by extension a UITextView which improperly calculates its sizeThatFits) when the font size is decreased from the font size that was used to create it. It doesn't happen on all NSAttributedStrings for which I do similar operations, so here's the steps to reproduce. Use a non-standard font that does not include the full unicode character set. Make sure the string includes characters in this "unsupported" set. iOS will

Fitting NSlayoutManager into UIView

怎甘沉沦 提交于 2019-12-12 06:37:11
问题 I have set up a UIView with NSLayoutManager (TextKit) and the UIView is placed in a UIScrollView. Im having trouble resizing the UIView to the size of the text so that It can be scrolled. Currently the text fills the screen but the scrollView doesn't really scroll to the rest of it. UIView Code: - (void)drawRect:(CGRect)rect { [super drawRect:rect]; NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; long value = [prefs integerForKey:@"Daven"]; if((int)value == 0){ string =

Which replacement method is called when editing an attributed string?

核能气质少年 提交于 2019-12-11 05:29:22
问题 NSMutableAttributedString defines two string replacement methods: func replaceCharacters(in range: NSRange, with str: String) and func replaceCharacters(in range: NSRange, with attrString: NSAttributedString) I have created a subclass of NSTextStorage which in its turn is a subclass of NSMutableAttributedString . In that subclass I overrode both of the above methods. To my surprise, the latter method (which passes an attributed replacement string) is never called when I type or paste

iOS 7 using an HTML string as an NSAttributedString AND setting the font?

亡梦爱人 提交于 2019-12-11 03:28:11
问题 I have a UITextView in which I'm trying to display some attributed text which comes in the form of HTML. It uses things like inline bolding and italicizing. The client now wants the font on this to change. However, whenever I change the font, it seems to disregard any of the HTML formatting. Is there any way to change the font while retaining the other formatting attributes, like bolding an italicizing? 回答1: The way I was able to get it to work was to prepend my string with <span style=\"font

How do I eliminate leading whitespace when computing word boundaries using boundingRectForGlyphRange in NSLayoutManager

爷,独闯天下 提交于 2019-12-11 02:08:02
问题 I am decomposing a multiline string into word boundaries on iOS. My solution centers around the boundingRectForGlyphRange method of NSLayoutManager. It ALMOST works, except that the rect for each word is a few pixels off to the right. In other words NSLayoutManager seems to be adding a leading space / indent on each line and I cannot find any way to override this behavior. I tried using NSLayoutManager.usesFontLeading as well as NSParagraphStyle.headIndent but without any results:

Customize underline pattern in NSAttributedString (iOS7+)

坚强是说给别人听的谎言 提交于 2019-12-10 15:05:39
问题 I'm trying to add a dotted underline style to an NSAttributedString (on iOS7+/TextKit). Of course, I tried the built-in NSUnderlinePatternDot : NSString *string = self.label.text; NSRange underlineRange = [string rangeOfString:@"consetetur sadipscing elitr"]; NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:string]; [attString addAttributes:@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle | NSUnderlinePatternDot)} range:underlineRange]; self

iOS文本布局探讨之二——关于TextKit框架中的字体描述

走远了吗. 提交于 2019-12-10 13:54:32
iOS文本布局探讨之二——关于TextKit框架中的字体描述 一、引言 UIFont是iOS开发中处理文本字体的类,关于UIFont的相关内容,以前的一篇博客有详细介绍,本片博客主要介绍关于动态字体的应用与字体描述类NSFontDescriptor的应用。 UIFont应用介绍: http://my.oschina.net/u/2340880/blog/397115 。 二、iOS系统中的动态字体 所谓动态字体,是指在应用使用中,用户可以动态调整字体的风格字号等。在iOS7及之后的iOS系统版本,TextKit框架中提供了一个新的类UIFontDescriptor。简单理解,UIFontDescriptor类是专门用来描述字体的,其中提供了许多方法可以直接创建出某种字体,也可以对字体进行设置和调整。动态字体也由这个类来创建。 在iOS7之后,系统增加了动态字体的功能,当用户在系统设置中修改字体的属性或者字号时,不仅会影响系统应用的字体,第三方应用的字体也可以进行相应调整。系统设置字体界面如下: 使用UIFontDescriptor类中的如下方法可以创建动态字体: //创建动态字体的字体描述类实例 + (UIFontDescriptor *)preferredFontDescriptorWithTextStyle:(NSString *)style;