core-text

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

北战南征 提交于 2019-11-27 12:32:40
问题 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. 回答1: I found a perfect

NSAttributedString and Links on iOS

谁说我不能喝 提交于 2019-11-27 12:31:28
问题 I am trying to add a hyperlink to certain parts of my text which is being handled and drawn using CoreText. According to Apple's docs on CoreText I should be using addAttribute:NSLinkAttributeName however on iOS (4.3) it says it doesn't know NSLinkAttributeName. In my document searches it looks like NSLinkAttributeName only still exists on the Mac. Is it available on iOS and I am just missing something? If it's not available how can I create a hyperlink on part of a text using

Core Text - select text in iPhone?

↘锁芯ラ 提交于 2019-11-27 10:12:10
问题 I need to render rich text using Core Text in my view (simple formatting, multiple fonts in one line of texts, etc.). I am wondering if text rendered this way can be selected by user using (standard copy / paste function)? 回答1: I implemented a text selection in CoreText. It is really a hard work... But it's doable. Basically you have to save all CTLine rects and origins using CTFrameGetLineOrigins (1) , CTLineGetTypographicBounds (2) , CTLineGetStringRange (3) and

NSAttributedString add text alignment

空扰寡人 提交于 2019-11-27 09:27:07
问题 How can I add text alignment attribute to an NSAttributedString to center the text? Edit: Am I doing anything wrong? It doesn't seem to change the alignment. CTParagraphStyleSetting setting; setting.spec = kCTParagraphStyleSpecifierAlignment; setting.valueSize = kCTCenterTextAlignment; CTParagraphStyleSetting settings[1] = { {kCTParagraphStyleSpecifierAlignment, sizeof(CGFloat), &setting}, }; CTParagraphStyleRef paragraph = CTParagraphStyleCreate(settings, sizeof(setting));

Core Text calculate letter frame in iOS

你离开我真会死。 提交于 2019-11-27 09:07:33
问题 I need to calculate exact bounding box for every each character (glyph) in NSAttributedString (Core Text). After putting together some code used to solve similar problems (Core Text selection, etc..), the result is quite good, but only few frames (red) are being calculated properly: Most of the frames are misplaces either horizontally or vertically (by tiny bit). What is the cause of that? How can I perfect this code?: -(void)recalculate{ // get characters from NSString NSUInteger len = [

How Can I Draw Image with Text Wrapping on iOS?

半城伤御伤魂 提交于 2019-11-27 08:22:15
I want to draw text just like the following style -- the image is always on the top right corner, and the text is around the image. Could anyone tell me how to implement this on iOS? Do I need to use Core Text? Thanks in advance! Yes, CoreText is the best way to do this. The code to do it is a little long to post here. Some code that may point you in the right direction is in the article "Clipping a CGRect to a CGPath." If the process for doing it is still confusing, ping me and I finally write the blog post I've been meaning to write on the subject. asetil Step 1 : Create an object inherited

NSAttributedString superscript styling

痴心易碎 提交于 2019-11-27 01:07:42
I want to superscript all the instances of ® character in a block of text (legal disclaimer, naturally ;)) and the default way NSAttributedString is not very good. If I just let the character be and only use unmodified NSString , it is rendered the same size as a capital letter and is placed approximately at the baseline. If I add the superscript attribute to NSAttributedString as follows: [attrStr setAttributes:@{(NSString *)kCTSuperscriptAttributeName : @1} range:NSMakeRange(locationOfReg, 1)]; The character is lifted off the baseline, its size is unchanged, but the line spacing is now

Vertical align with Core Text?

北城余情 提交于 2019-11-26 20:59:36
问题 How do I change the vertical alignment of the text in a CTFramesetter frame? I want my text to be in the middle instead of being at the top . I am using Core Text framework. There is a setting of the paragraph to change horizontal aligment but not vertical. 回答1: Finally figured it out ... CGRect boundingBox = CTFontGetBoundingBox(font); //Get the position on the y axis float midHeight = self.frame.size.height / 2; midHeight -= boundingBox.size.height / 2; CGPathAddRect(path, NULL, CGRectMake

How to split long NSString into pages

人走茶凉 提交于 2019-11-26 20:15:31
问题 I have a long NSString I want to display over a couple of pages. But to do this, I need to find out how much text will actually fit on the page. [NSString sizeWithFont: ...] Is not enough, it will just tell me if the text fits in the rectangle or not, if its does not, it will silently truncate the string, but it won't tell me where it truncated! I need to know the first word that does not fit on the page, so I can split the string and draw that part of it on the next page. (and repeat) Any

How Can I Draw Image with Text Wrapping on iOS?

自闭症网瘾萝莉.ら 提交于 2019-11-26 14:07:39
问题 I want to draw text just like the following style -- the image is always on the top right corner, and the text is around the image. Could anyone tell me how to implement this on iOS? Do I need to use Core Text? Thanks in advance! 回答1: Yes, CoreText is the best way to do this. The code to do it is a little long to post here. Some code that may point you in the right direction is in the article "Clipping a CGRect to a CGPath." If the process for doing it is still confusing, ping me and I