3
votes

I am using CoreText to draw text to my table view cells as I implemented the fast scrolling technique. Links in my text are a different color and respond to clicks, but I cannot figure out how to get the links to look like they are being clicked i.e. change color when tapped then change back. I have seen this in multiple apps, but not sure how it is done. Can this be done with CoreText or do I need to use something else?

I know this can be done with UILabels but that defeats the purpose of drawing text directly in the cell's content view.

Thanks.

2

2 Answers

3
votes

Each time you want to change the color of the text, you need to send a -setNeedsDisplayInRect: to the view in which you are drawing the text. In addition, set a variable corresponding to the text color.

When the view redraws and invokes your drawLayer:inContext:, make sure that kCTForegroundColorAttributeName is set to the correct color (based off of the variable you set) and redraw your text.

You can also use a similar technique but with the methods in UIKit/UIStringDrawing.h rather than Core Text.

0
votes

This may help you

<style>
    button:focus {
        color: red;
    }
</style>

<button>Hello</button>

The focus pseudo class of CSS changes the CSS of an element when element is being focused

Focusable elements are a, input, textarea, button, select, object

In mobiles / tablets, when these elements are tapped, these will be focused and in this example, color of text in button will change to red.