nsattributedstring

What is the equivalent of NSLineBreakMode in iOS 7 attributed strings drawing methods?

心不动则不痛 提交于 2019-11-29 01:42:10
问题 There was a method - (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font lineBreakMode:(NSLineBreakMode)lineBreakMode alignment:(NSTextAlignment)alignment; which I must replace now for iOS 7. I get as far as NSDictionary *attributes = @{NSFontAttributeName: font}; [self drawInRect:rect withAttributes:attributes]; but how to specify the line break mode like word wrap? I searched documentation of Attributed string drawing symbols but no mention of line break mode. Is this automartically

CoreText. How Do I Calculate the Bounding Box of an Attributed String?

 ̄綄美尐妖づ 提交于 2019-11-29 01:13:02
问题 In CoreText it is easy ask: "for a given rectangle how much of this attributed string will fit?". CTFrameGetVisibleStringRange(rect).length Will return where in the string the next run of text should begin. My question is: "given an attributed string and a width, what rect height do I need to completely bound the attributed string?". Does the CoreText framework provide tools to do this? Thanks, Doug 回答1: What you need is CTFramesetterSuggestFrameSizeWithConstraints(), you can use it like so:

NSBackgroundColorAttributeName-like attribute in NSAttributedString on iOS?

天涯浪子 提交于 2019-11-28 23:36:00
I was planning on using NSAttributedString to highlight portions of strings with the matching query of a user's search. However, I can't find an iOS equivalent of NSBackgroundColorAttributeName —there's no kCTBackgroundColorAttributeName . Does such a thing exist, similar to the way NSForegroundColorAttributeName becomes kCTForegroundColorAttributeName ? No, such an attribute doesn't exist in Core Text, you'll have to draw your own rectangles underneath the text to simulate it. Basically, you'll have to figure out which rectangle(s) to fill for a given range in the string. If you do your

Center two fonts with different different sizes vertically in an NSAttributedString

我是研究僧i 提交于 2019-11-28 21:55:50
问题 I use NSAttributedString to generate a string with two different sizes. By default, its bottom alignment looks like this: But I want to center it vertically, like this: To be clear, this is a single attributed string, not two or more. This is a simplified example to describe my question, what I'd actually like to do is more complex. 回答1: I'd say the easiest thing to do is just manipulate the NSBaselineOffsetAttributeName attribute for the text in question: NSBaselineOffsetAttributeName The

replace entire text string in NSAttributedString without modifying other attributes

喜你入骨 提交于 2019-11-28 21:37:26
问题 I have a reference to NSAttributedString and i want to change the text of the attributed string. I guess i have to created a new NSAttributedString and update the reference with this new string. However when i do this i lose the attributed of previous string. NSAttributedString *newString = [[NSAttributedString alloc] initWithString:text]; [self setAttributedText:newString]; I have reference to old attributed string in self.attributedText . How can i retain the previous attributed in the new

NSAttributedString initWithData and NSHTMLTextDocumentType crash if not on main thread

不羁的心 提交于 2019-11-28 20:52:19
calling NSAttributedString * as = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)} documentAttributes:nil error:nil]; on other than main thread, results in a crash 1 0x194b861fc <redacted> 2 0x19801d31c <redacted> 3 0x198010eb4 _os_once 4 0x19801aa2c pthread_once 5 0x195a0858c <redacted> 6 0x195a07c78 WebKitInitialize 7 0x18bb38918 <redacted> 8 0x10020cdf0 _dispatch_client_callout 9 0x10020dcfc dispatch_once_f 10

What is the equivalent of Android's “Spannable” in Objective-C

被刻印的时光 ゝ 提交于 2019-11-28 19:48:02
Im on an iOS app that should able to highlight text, and make it clickable too. I read about NSAttributedString in iOS but it still more complicated than Spannable in android. Is there any other Objective c way to do that, if not; what should i do using NSAttributedString to highlight a paragraph word by word, and how to make my text clickable. Update: What exactly i want that each word should be clickable and can be highlighted as a single word in one paragraph. I found a perfect solution using UITextView , it will make every word in within the UITextView clickable. Firstly, Create an

Make link in UILabel.attributedText *not* blue and *not* underlined

百般思念 提交于 2019-11-28 19:42:43
问题 I want some words within my OHAttributedLabel to be links, but I want them to be colors other than blue and I don't want the underline. This is giving me a blue link with underlined text: -(void)createLinkFromWord:(NSString*)word withColor:(UIColor*)color atRange:(NSRange)range{ NSMutableAttributedString* mutableAttributedText = [self.label.attributedText mutableCopy]; [mutableAttributedText beginEditing]; [mutableAttributedText addAttribute:kOHLinkAttributeName value:[NSURL URLWithString:@

UITextView: Disable selection, allow links

狂风中的少年 提交于 2019-11-28 18:38:41
I have a UITextView which displays an NSAttributedString . The textView's editable and selectable properties are both set to false . The attributedString contains a URL and I'd like to allow tapping the URL to open a browser. But interaction with the URL is only possible if the selectable attribute is set to true . How can I allow user interaction only for tapping links, but not for selecting text? I find the concept of fiddling with the internal gesture recognizers a little scary, so tried to find another solution. I've discovered that we can override point(inside:with:) to effectively allow

Storing NSAttributedString Core Data

喜夏-厌秋 提交于 2019-11-28 18:19:55
I am trying to store an NSAttributedString to a Core Data SQL store. I have the property set as a "transformable", it is optional and it is NOT transient or indexed and the value transformer name is set to default "NSKeyedUnarchiveFromData". In the .xcdatamodel and generated the managed object class which has this in the .h: @property (nonatomic, retain) id Text; (I have tried changing id to NSAttributedString *Text) and this in the .m: @dynamic Text; I look through and set the ".text" property of my NSManagedObject to the attributed string then when completed I do: NSError *error = nil;