core-text

Draw underlined / strikethrough text ( MULTILINE STRING )?

 ̄綄美尐妖づ 提交于 2019-11-29 02:29:56
I have to draw underlined-multiline text with all types of text alignment. I have searched on forums and got some results like: http://davidjhinson.wordpress.com/2009/11/26/underline-text-on-the-iphone/ http://forums.macrumors.com/showthread.php?t=561572 But all draw text for single line only. while i have multi-line text. The situation even become worse when the text alignment is centered. I searched and found that in iphone-sdk-3.2 there are some core-text attributes for underlining a text but no idea how to use that. Besides if I use these my problem would not be solved fully. As I have to

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

Text/font rendering in OpenGLES 2 (iOS - CoreText?) - options and best practice?

ぃ、小莉子 提交于 2019-11-28 22:41:24
问题 There are many questions on OpenGL font rendering, many of them are satisfied by texture atlases (fast, but wrong), or string-textures (fixed-text only). However, those approaches are poor and appear to be years out of date (what about using shaders to do this better/faster?). For OpenGL 4.1 there's this excellent question looking at "what should you use today ?": What is state-of-the-art for text rendering in OpenGL as of version 4.1? So, what should we be using on iOS GL ES 2 today? I'm

How can you load a font (TTF) from a file using Core Text?

两盒软妹~` 提交于 2019-11-28 20:36:58
问题 Prior to OSX 10.6, ATSFontActivateFromFileSpecification/ATSFontActivateFromFileReference were available and could be used to load a font from a file. I can't find anything similar in Core Text. 回答1: You can get a CTFontRef from a font file by going via a CGFontRef : CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR("/path/to/font"), kCFURLPOSIXPathStyle, false); CGDataProviderRef dataProvider = CGDataProviderCreateWithURL(url); CGFontRef theCGFont =

NSAttributedString and Links on iOS

 ̄綄美尐妖づ 提交于 2019-11-28 19:51:55
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 NSMutableAttributedString and CoreText? Thanks Jeremy has published JTextView , a Core Text-based UITextView analogue

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

Multi-line NSAttributedString with truncated text

回眸只為那壹抹淺笑 提交于 2019-11-28 17:51:19
问题 I need a UILabel subcass with multiline attributed text with support for links, bold styles, etc. I also need tail truncation with an ellipsis. None of the open source code that supports attributed text inside UILabels ( TTTAttributedLabel , OHAttributedLabel , TTStyledTextLabel ) seem to support tail truncation for multi-line text. Is there an easy way to get this? 回答1: Hi I am the developer of OHAttributedLabel. There is no easy way to achieve this (as explained in the associated issue I

Core Text's CTFramesetterSuggestFrameSizeWithConstraints() returns incorrect size every time

痞子三分冷 提交于 2019-11-28 17:40:34
According to the docs, CTFramesetterSuggestFrameSizeWithConstraints () "determines the frame size needed for a string range". Unfortunately the size returned by this function is never accurate. Here is what I am doing: NSAttributedString *string = [[[NSAttributedString alloc] initWithString:@"lorem ipsum" attributes:nil] autorelease]; CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef) string); CGSize textSize = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0,0), NULL, CGSizeMake(rect.size.width, CGFLOAT_MAX), NULL); The

Core Text - select text in iPhone?

最后都变了- 提交于 2019-11-28 17:07:24
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)? 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 CTLineGetOffsetForStringIndex (4) . The line rect can be calculated using the origin (1) , ascent (2) , descent (2) and offset (3)(4) as