core-text

Replace UITextViews text with attributed string

情到浓时终转凉″ 提交于 2019-11-29 21:54:29
I have a UITextView and when the user is entering text into it, I want to format the text on the fly. Something like syntax highlighting... For that I'd like to use UITextView ... Everything works fine expect one problem: I take the text from the text view and make an NSAttributedString from of it. I make some edits to this attributed string and set it back as the textView.attributedText . This happens everytime the user types. So I have to remember the selectedTextRange before the edit to the attributedText and set it back afterwards so that the user can continue typing at the place he was

Multi-line NSAttributedString with truncated text

女生的网名这么多〃 提交于 2019-11-29 21:36:50
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? Hi I am the developer of OHAttributedLabel . There is no easy way to achieve this (as explained in the associated issue I opened on the github repository of my project), because CoreText does not offer such feature. The only way to

Using CoreText and touches to create a clickable action

寵の児 提交于 2019-11-29 21:08:31
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 drawing code happens in -drawRect: (I've left it out for brevity). My touch handler however, while

Core Text - NSAttributedString line height done right?

萝らか妹 提交于 2019-11-29 20:25:41
I'm completely in the dark with Core Text's line spacing. I'm using NSAttributedString and I specify the following attributes on it: - kCTFontAttributeName - kCTParagraphStyleAttributeName From this the CTFrameSetter gets created and drawn to context. In the paragraph style attribute I'd like to specify the height of the lines. When I use kCTParagraphStyleSpecifierLineHeightMultiple each line receives padding at the top of the text, instead of the text being displayed in the middle of this height. When I use kCTParagraphStyleSpecifierLineSpacing a padding is added to the bottom of the text.

CGContextSelectFont equivalent

那年仲夏 提交于 2019-11-29 17:07:09
问题 In iOS7 CGContextSelectFont is deprecated. Deprecation message says that I have to use Core Text, but I don't know which is the exact equivalent of this piece of code: CGContextSelectFont(context, "Helvetica", kBarLabelSize, kCGEncodingMacRoman); CGContextSetTextDrawingMode(context, kCGTextFill); CGContextSetRGBFillColor(context, 0, 0, 0, 1.0); CGContextSetTextMatrix (context, CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, 0.0)); CGContextShowTextAtPoint(context, barX, barY, [@"Some text"

Can I use NSAttributedString in Core Text in iOS?

走远了吗. 提交于 2019-11-29 12:49:14
问题 I'm trying to work out how to take an NSAttributedString and use it in Core Text on the iPad. I watched one of the WWDC videos (110) which has slides (but no source code) and it describes how to create an NSAttributedString, then just put it into a CTFramesetterRef: CTFontRef helveticaBold = CTFontCreateWithName( CFSTR("Helvetica-Bold"), 24.0, NULL); NSString* unicodeString = NSLocalizedString(@"TitleString", @"Window Title"); CGColorRef color = [UIColor blueColor].CGColor; NSNumber*

Issue with CoreText CTFrameGetLineOrigins in Swift

纵然是瞬间 提交于 2019-11-29 11:56:38
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 ctLinesArray = nsLinesArray as Array var originsArray: Array<CGPoint> = CGPoint[]() //var originsArray

Get each line of text in a UILabel

回眸只為那壹抹淺笑 提交于 2019-11-29 11:38:30
I'm trying to add each line in a UILabel to an array, but the code I'm using doesn't appear to be terribly accurate. func getLinesArrayOfStringInLabel(label:UILabel) -> [String] { guard let text: NSString = label.text as? NSString else { return [] } let font:UIFont = label.font let rect:CGRect = label.frame let myFont: CTFont = CTFontCreateWithName(font.fontName as CFString, font.pointSize, nil) let attStr:NSMutableAttributedString = NSMutableAttributedString(string: text as String) attStr.addAttribute(NSAttributedStringKey.font, value:myFont, range: NSMakeRange(0, attStr.length)) let

How do I add tab stops to an NSAttributedString and display in a UITextView

送分小仙女□ 提交于 2019-11-29 10:28:15
问题 I'm creating an iOS app, and I would like to display an attributed string with specific tab stops specified in a UITextView. I would also like to draw them directly into UIViews using Core Text in drawRect. I would like (if possible) for the same attributed string to be used in both scenarios. So, in my app, I create an CFAttributedStringRef or an NSAttributedString and apply a CTParagraphStyle attribute to it. Then, I attempt to display the attributed string in a UITextView and I get a crash

Inverse UIlabel text color when its frame intersects an UIView

岁酱吖の 提交于 2019-11-29 07:48:55
问题 Hi Im trying to change the text color of a UILabel in the case when the labels rect intersects an UIView, i was thinking maybe there is a property or something i can use. Like in the image below: Did someone meet this issue before, or what should i read to start doing this thing ? Thanks in advance 回答1: Good puzzle! Here's what I would do: Two UIViews. Let's call one the background and the other the progressBar. progressBar is stacked on top of background with the same origin on their common