core-text

Using CoreText and touches to create a clickable action

≡放荡痞女 提交于 2019-12-18 10:24:55
问题 I have some code in a view which draws some attributed text using CoreText. In this, I'm searching for urls and making them blue. The idea is to not bring in all the overhead of a UIWebView just to get clickable links. Once a user taps on that link (not the whole table view cell), I want to fire off a delegate method which will then be used to present a modal view which contains a web view going to that url. I'm saving the path and the string itself as instance variables of the view, and the

Issue with CoreText CTFrameGetLineOrigins in Swift

柔情痞子 提交于 2019-12-18 07:10:16
问题 I have the following code working in Objective-C NSArray *lines = (NSArray *)CTFrameGetLines((__bridge CTFrameRef)columnFrame); CGPoint origins[[lines count]]; CTFrameGetLineOrigins((__bridge CTFrameRef)columnFrame, CFRangeMake(0, 0), origins); But when ported to Swift, the compiler complains with a Cannot convert the expression´s ´Void´to type ´CMutablePointer<CGPoint> in the CTFrameGetLineOrigins line let nsLinesArray: NSArray = CTFrameGetLines(ctFrame) // Use NSArray to bridge to Array let

NSBackgroundColorAttributeName-like attribute in NSAttributedString on iOS?

不问归期 提交于 2019-12-18 02:42:18
问题 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 ? 回答1: 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

How does line spacing work in Core Text? (and why is it different from NSLayoutManager?)

会有一股神秘感。 提交于 2019-12-17 17:25:14
问题 I'm trying to draw text using Core Text functions, with a line spacing that's as close as possible to what it would be if I used NSTextView. Take this font as an example: NSFont *font = [NSFont fontWithName:@"Times New Roman" size:96.0]; The line height of this font, if I would use it in an NSTextView is 111.0. NSLayoutManager *lm = [[NSLayoutManager alloc] init]; NSLog(@"%f", [lm defaultLineHeightForFont:font]); // this is 111.0 Now, if I do the same thing with Core Text, the result is 110.4

How to copy a NSMutableAttributedString

一曲冷凌霜 提交于 2019-12-13 20:44:33
问题 I'm just wondering how I can make a copy of an NSMutableAttributedString . I have a property called text that I'd like to save its contents at a certain point and revert back to it in case something happens. I've tried making a property called textCopy where I can save it to with @property (nonatomic, copy) but I get a runtime error when I do this: -[NSConcreteAttributedString insertAttributedString:atIndex:]: unrecognized selector sent to instance. How would I accomplish this? Updated with

RE: autorotating, scrolling, bulleted, indented UIScrollView with attributed strings

你。 提交于 2019-12-13 18:24:06
问题 This was a doozy to produce, and since I had much help from SO contributors in putting it together, it seems fair to post the results (as an answer, below). If you’re looking for examples involving attributed strings in iOS and Core Text and scrolling, here they are assembled. A few extra points: Wrapping: This is done by the attributed string’s lineBreakMode, which defaults to wrapping. You won’t be able to retrieve the soft line breaks from the string (unlike in Cocoa, where NSTextView puts

Superscript, Subscript text with Core Text iPhone

只愿长相守 提交于 2019-12-13 18:11:37
问题 Can anyone explain me, How to draw superscript and subscript alphabets with Core Text? Thanks. 回答1: I noticed that this question is a bit old, I hope you still require assistance in this matter and that this post will help you. you can use NSAttributedString (or its mutable counterpart NSMutableAttributedString) to assign different attributes (such as font, both name and size) to specific ranges of a single string. Superscript and subscript are not natively supported by core text and to make

How to set tab stop in CoreText

╄→гoц情女王★ 提交于 2019-12-13 09:54:28
问题 I want to set the tab stop in CoreText. I really need the code. The example is more good. Anyone can help me? 回答1: First off, have you read the CoreText programming guide? If so, take a look at the CTTextTab reference - specifically the CTTextTabCreate method. This should be more than enough to set you in the right direction. (We're not here to write your code for you.) 来源: https://stackoverflow.com/questions/4569190/how-to-set-tab-stop-in-coretext

Core Text Memory allocation issue

守給你的承諾、 提交于 2019-12-13 06:25:05
问题 I inspected my app with the allocation instrument and I discovered that this code down here cause me an allocation issue. The method returns the suggested height of a squared area filled with the passed attributed string; I need this in order to calculate how much space I need to draw that text and then generating book pages: - (CGFloat)boundingHeightForWidth:(CGFloat)inWidth ForAttributedString:(NSAttributedString *)attributedString { CTFramesetterRef framesetter =

NSSuperscriptAttributeName show error?

狂风中的少年 提交于 2019-12-13 04:05:58
问题 I am trying to create a subscripted text in iphone using NSMutableAttributedString. But the "NSSuperscriptAttributeName" show some error " undeclared identifier ". How can i solve it? NSDictionary * superscriptAttrs = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1] forKey:NSSuperscriptAttributeName]; NSAttributedString * st = [[NSAttributedString alloc] initWithString:@"st" attributes:superscriptAttrs]; 回答1: Assuming that you're on iOS, you need to use a different set of