Configuring Text Styling Attributes
Send Feedback

Glossary Item Box

Topic Overview

Purpose

This topic provides a conceptual overview of the text styling attributes in the IGLabel control and demonstrates how to configure it using a code example.

In this topic


Introduction

Text styling summary

Text attributes are used to decorate the displayed text using an NSRange or a regular expression search string through these two methods; addAttributes:range:, and addAttributes:forRegEx:error:. Attributes allow you to adjust these text characteristics; bold appearance; font used; text foreground color; italic appearance; kern spacing; text stroke color and width; interaction of text through tap; and underline appearance and color.


Text Styling Attributes Reference

Introduction

Text attributes are key/value pairs added to an NSDictionary where the key defines the text attribute and the value contains the specific setting for that key. The following code snippet exemplifies an NSDictionary.

In C#:

NSMutableDictionary attributes = new NSMutableDictionary();
attributes.Add(IGLabelConstants.IGTextStyleBoldAttributeName, UIFont.SystemFontOfSize(24.0f));
attributes.Add(IGLabelConstants.IGTextStyleForegroundColorAttributeName, UIColor.DarkTextColor);
attributes.Add(IGLabelConstants.IGTextStyleTapAttributeName, new NSString("http://infragistics.com"));

In Objective-C:

NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
                [UIFont systemFontOfSize:24], IGTextStyleBoldAttributeName,
                [UIColor darkTextColor], IGTextStyleForegroundColorAttributeName,
                @"http://infragistics.com", IGTextStyleTapAttributeName, nil];

Text styling attributes reference chart

The following table summarizes the text styling attributes and a description of their expected value.

Text Attribute

Description

IGTextStyleBoldAttributeName

The value used with this key is a UIFont.

IGTextStyleFontAttributeName

The value used with this key is a UIFont.

IGTextStyleForegroundColorAttributeName

The value used with this key is a UIColor.

IGTextStyleItalicAttributeName

The value used with this key is a UIFont.

IGTextStyleKernAttributeName

The value used with this key is an NSNumber with float.

IGTextStyleStrokeColorAttributeName

The value used with this key is a UIColor.

IGTextStyleStrokeWidthAttributeName

The value used with this key is an NSNumber with float.

IGTextStyleTapAttributeName

The value used with this key is an NSObject.

IGTextStyleUnderlineAttributeName

The value used with this key is an NSNumber with int where an int value of 1 means on, 0 means off.

IGTextStyleUnderlineColorAttributeName

The value used with this key is a UIColor.



Adding Text Styling to Text Displayed on the IGLabel – Code Example

Description

The code below adds text style and tap attributes which apply a bold and dark text appearance to the word “fox,” and causes the IGLabelDelegate if used, to call the labelTap:tapValue: method whenever the user taps the word.

Prerequisites

This code example requires the inclusion of the IG framework, detail about how to add this framework can be found in the Adding the Label Framework File topic.

Code

In C#:

label.Text = "The quick brown fox jumped over the lazy dogs.";
NSMutableDictionary attributes = new NSMutableDictionary();
attributes.Add(IGLabelConstants.IGTextStyleBoldAttributeName, UIFont.SystemFontOfSize(24.0f));
attributes.Add(IGLabelConstants.IGTextStyleForegroundColorAttributeName, UIColor.DarkTextColor);
attributes.Add(IGLabelConstants.IGTextStyleTapAttributeName, new NSString("The word 'fox' was tapped."));
NSError error;
label.AddAttributes(attributes, "fox", out error);

In Objective-C:

label.text = @"The quick brown fox jumped over the lazy dogs.";
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:    [UIFont systemFontOfSize:24], IGTextStyleBoldAttributeName,    [UIColor darkTextColor], IGTextStyleForegroundColorAttributeName,    @"The word 'fox' was tapped.", IGTextStyleTapAttributeName, nil];
NSError *error;[label addAttributes:attributes forRegEx:@"fox" error:&error];

Related Content

Topics

The following topics provide additional information related to this topic.

Topic

Purpose

The topics in this group cover enabling, configuring, and using the IGLabel control’s supported features.