Created
June 23, 2012 07:46
-
-
Save jverkoey/2977427 to your computer and use it in GitHub Desktop.
NIAttributedLabel Example 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NIAttributedLabel* label = [[NIAttributedLabel alloc] initWithFrame:CGRectZero]; | |
label.numberOfLines = 0; | |
label.lineBreakMode = UILineBreakModeWordWrap; | |
label.autoresizingMask = UIViewAutoresizingFlexibleDimensions; | |
label.frame = CGRectInset(self.view.bounds, 20, 20); | |
label.font = [UIFont fontWithName:@"AmericanTypewriter" size:15]; | |
// In order to handle the events generated by the user tapping a link we must implement the | |
// delegate. | |
label.delegate = self; | |
// By default the label will not automatically detect links. Turning this on will cause the label | |
// to pass through the text with an NSDataDetector, highlighting any detected URLs. | |
label.autoDetectLinks = YES; | |
// By default links do not have underlines and this is generally accepted as the standard on iOS. | |
// If, however, you do wish to show underlines, you can enable them like so: | |
label.linksHaveUnderlines = YES; | |
label.text = | |
@"A screen on the dash flickers and displays an artist's rendition of the planet." | |
// We can use \n characters to separate lines of text. | |
@"\nSigned beneath the image: tenach.deviantart.com"; | |
NSRange linkRange = [label.text rangeOfString:@"an artist's rendition of the planet"]; | |
// Explicitly adds a link at a given range. | |
[label addLink:[NSURL URLWithString:@"http://th04.deviantart.net/fs71/300W/f/2010/145/c/9/Planet_Concept_1_by_Tenach.jpg"] | |
range:linkRange]; | |
[self.view addSubview:label]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment