Skip to Main Content
Cocoa Programming for OS X: The Big Nerd Ranch Guide
book

Cocoa Programming for OS X: The Big Nerd Ranch Guide

by Aaron Hillegass, Adam Preble, Nate Chandler
April 2015
Intermediate to advanced content levelIntermediate to advanced
556 pages
17h 47m
English
Big Nerd Ranch Guides
Content preview from Cocoa Programming for OS X: The Big Nerd Ranch Guide

NSAttributedString

Sometimes, you want to display a string that has certain attributes for a range of characters. For example, suppose that you want to display the string “Big Nerd Ranch” and want the letters 0 through 2 to be bold, the letters 4 through 7 to be orange, and the letters 9 through 13 to be subscripts.

When dealing with a range of numbers, Cocoa uses the struct NSRange. NSRange has two members, location and length, which are both integers. The location is the index of the first item, and the length is the number of items in the range. You can use the function NSMakeRange() to create an NSRange, but in Swift it is more expedient to use the range expression initializer: NSRange(0...4).

To create strings with attributes ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Cocoa and Objective-C: Up and Running

Cocoa and Objective-C: Up and Running

Scott Stevenson
Learning Cocoa with Objective-C, 4th Edition

Learning Cocoa with Objective-C, 4th Edition

Paris Buttfield-Addison, Jonathon Manning, Tim Nugent

Publisher Resources

ISBN: 9780134077130Purchase book