core-text

CoreText and strikethrough on iPhone

徘徊边缘 提交于 2019-12-05 19:01:00
I'm currently struggling with the need to display strikethrough text in many UITableViewCell s. Something that written in HTML would looke like <strike>€99</strike> save 50% => now €49 I don't want to use a UIWebView just for a single line of text, especially that it's used in small UITableViewCell s. I know there are reusable cells and all, but I'd like to keep things the more memory-efficient way possible. So... I'm using NSAttributedString s, with the help of AliSoftware's UILabel -replacement OHAttributedLabel . The fact that it's only available starting with iOS 4.0 is no problem, as we

CATextLayer wrapped sizeToFit?

橙三吉。 提交于 2019-12-05 03:26:04
If I set textLayer.wrapped = YES , how do I resize textLayer to contain the wrapped text? I.e., how do I get the new height of the textLayer ? Basically, I want something like -[UILabel sizeToFit] . The first thing you need to do is get the size of the text. Thankfully, the NSString UIKit Additions Reference offers a method to do exactly that: - (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode That will give you a CGSize that you can then use to set the frame of your UILabel or whatever subclass of UIView that you're using. So,

NSAttributedString - get font attributes

我们两清 提交于 2019-12-05 02:15:32
I need to get info about my attributed string but can't figure out how. I'm getting this dictionary: 2013-11-04 18:06:10.628 App[1895:60b] { NSColor = "UIDeviceWhiteColorSpace 0.3 1"; NSFont = "<UICTFont: 0x17d8d4c0> font-family: \".HelveticaNeueInterface-MediumP4\"; font-weight: bold; font-style: normal; font-size: 17.00pt"; NSUnderline = 0; } It is easy to check the underline with: [attrs objectForKey:@"NSUnderline"] But how to get info about font like the font-style, font-weight etc. Thanks for any help You get the font from: UIFont *font = attrs[NSFontAttributeName]; The issue is

How to get the real height of text drawn on a CTFrame

流过昼夜 提交于 2019-12-05 00:10:04
问题 I have a certain amount of text that fill some CTFrame (more than one). To create all frames (one for each page), I'm filling one frame, getting the text that didn't fitted the frame using CTFrameGetVisibleStringRange and repeating this process until all text is processed. On all frames, except the last, the text occupies the same height of page. On last frame I'd like to know the real height the text occupies, to know where I could start drawing more text. Is there any way to do this? UPDATE

How can I determine if a specific emoji character can be rendered by an iOS device?

喜你入骨 提交于 2019-12-04 19:10:48
With the release of iOS 9.1, we got a lot of cool new emoji like taco (🌮)! I'm working on an application where I'd like to show the new emoji characters on devices where they are supported but keep them hidden on devices where they are not. Is there a way to determine if a given emoji character (contained in an NSString) can be rendered on the device the app is running on? After quite a bit of digging on SO and experimenting I've come up with a solution which I will post as an answer below, but please let me know if there's a better way. // Determine if the emoji character provided in the

Get unicode character by glyph index in a CTFontRef or CGFontRef object

别等时光非礼了梦想. 提交于 2019-12-04 14:55:45
The CTFontRef provides excellent method such as CTFontGetGlyphsForCharacters for mapping character(s) to glyph(s). My question is, is there any method for invert mapping? That is say, can I get characters(s) by given glyph(s)? Since I found there is a CTFontCopyCharacterSet for getting all supported characters, I think there will be some nice solutions. I think you may end up having to parse the font’s mapping tables yourself. You can obtain access to the tables using CGFontCopyTableForTag() ; the table you're after is the ' cmap ' table, the format of which is documented here: http://www

Swift - Playground - Core Graphics / Core Text / Custom View

风流意气都作罢 提交于 2019-12-04 12:43:13
问题 Question I'm attempting to make a custom UIView component in swift playground. I've been able to figure out how to do everything except for render text correctly. I'm not sure if i'm supposed to do this via Core Graphics or Core Text or exactly how to get it working correctly. As you can see in the image below I want to render text both upside down and right side up on either side of my custom View Component I've tried various ways to get the text to work but I keep running aground. If

NSTextAttachment image not showing when drawing using CoreText

柔情痞子 提交于 2019-12-04 11:13:36
For some reason I'm unable to get NSTextAttachment images to draw when using core text, although the same image would display fine when the NSAttributedString is added to an UILabel. On iOS this rendering will give empty spaces for the NSTextAttachments, for OS X, a placeholder [OBJECT] square image is rendered for each NSTextAttachment instead. Is there something else that needs to be done in order to render images with CoreText? The rendering code: CGFloat contextHeight = CGBitmapContextGetHeight(context); CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge

CoreText crashes when run in multiple threads

久未见 提交于 2019-12-04 09:11:11
问题 I have a very weird problem with core text, which sometimes randomly and sometimes reproducibly crashes my application. I use it to lay out and render a couple of pages. I do this asynchronously in the background to not block the user interface. While this works fine in general, it sometimes crashes. All these crashes happen on the very same line: framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)myText); In fact, they also also seem to come from a similar point in

CTFontGetGlyphsForCharacters always returns false

▼魔方 西西 提交于 2019-12-04 08:25:55
Please help me understand the problem with the following code: NSString *fontName = @"ArialMT"; CGFloat fontSize = 20.0; CTFontRef fontRef = CTFontCreateWithName((CFStringRef)fontName, fontSize, NULL); NSString *characters = @"ABC"; NSUInteger count = characters.length; CGGlyph glyphs[count]; if (CTFontGetGlyphsForCharacters(fontRef, (const unichar*)[characters cStringUsingEncoding:NSUTF8StringEncoding], glyphs, count) == false) NSLog(@"*** CTFontGetGlyphsForCharacters failed."); Any help is appreciated. rob mayoff You are getting a C string containing UTF-8 encoded characters and then casting