CoreText - change text color on click

I am using CoreText to draw text in table view cells when I implemented fast scrolling method. The links in my text are color-coded and responsive, but I can't figure out how to get the links to look like they were clicked, i.e. change the color on click and then change it. I've seen this in several applications, but not sure how it's done. Can this be done using CoreText or do I need to use something else?

I know it can be done with UILabels, but it hurts the purpose of drawing text directly into the cell's content view.

Thank.

+3


source to share


1 answer


Every time you want to change the color of the text, you need to send -setNeedsDisplayInRect: to the view where you are drawing the text. Also, set the variable to match the text color.

When the view redraws and calls your drawLayer: inContext: make sure the parameter is kCTForegroundColorAttributeName

set to the correct color (based on the given variable) and redraw the text.



You can also use a similar method, but with the methods in UIKit / UIStringDrawing.h, not in the body text.

+3


source







All Articles