Create Tappable Content Within the IGLabel (Obj-C)

Torrey Betts / Wednesday, April 6, 2016

What is the IGLabel?

What is the IGLabel?

The IGLabel is an iOS control for creating rich text labels. It works similarly to the generic UILabel and applies styles to text in a similar fashion that is done when using attributed strings. It is also based on Core Text to boost performance and functionality over the generic UILabel.

What is Tappable Content?

Tappable content is series of characters, words or sentences that allow interaction by tapping them. The IGLabel allows this interaction by setting an attribute over a matching regular expression or specific text location. When tappable content is tapped using the IGLabel, the labelTap:tapText:tapValue IGLabelDelegate method is called. This method provides the label tapped, the text receiving the tap and the value applied to the text through the styling attribute.

How Do I Create Tappable Content?

The first step in creating tappable content is to set the text property on an instance of the IGLabel.

_label.text = @"The IGLabel contains tappable content.";

Next create an NSDictionary containing the tap attribute. Any NSObject can be used for the tap attribute.

NSDictionary *attributes = @{IGTextStyleTapAttributeName : @"Imaginary Value"};

Finally, add the attributes dictionary to the IGLabel.

[_label addAttributes:attributes forRegEx:@"tappable\\scontent" error:nil];

Once the attribute has been added to the IGLabel, the text "tappable content" can be tapped.

Where Can I Learn More?

The reference links below provide more information about the IGLabel and the styling aspects it supports.

By Torrey Betts