Supports adding text effects or click events and text effect events
Source code WPAttributedMarkup. WPAttributedMarkup can add text effects or click events to a keyword in the Label. A keyword in the Label can change the font features, such as color, bold, and underline. You can also add click events for a keyword.
<Ignore_js_op>
Usage:
You can set the label attributes after creating different styles. For example:
// Example using fonts and colours
NSDictionary * style1 =@ {@ "body": [UIFont fontWithName: @ "HelveticaNeue" size: 18.0],
@ "Bold": [UIFont fontWithName: @ "HelveticaNeue-Bold" size: 18.0],
@ "Red": [UIColor redColor]};
// Example using arrays of styles, dictionary attributes for underlining and image styles
NSDictionary * style2 =={ @ "body ":
@ [UIFont fontWithName: @ "HelveticaNeue-Bold" size: 18.0],
[UIColor darkGrayColor],
@ "U": @ [UIColor blueColor],
@ {NSUnderlineStyleAttributeName: @ (kCTUnderlineStyleSingle | kCTUnderlinePatternSolid )}
],
@ "Thumb": [UIImage imageNamed: @ "thumbIcon"]};
// Example using blocks for actions when text is tapped. Uses the 'link' attribute to style the links
NSDictionary * style3 =@ {@ "body": [UIFont fontWithName: @ "HelveticaNeue" size: 22.0],
@ "Help": [WPAttributedStyleAction styledActionWithAction: ^ {
NSLog (@ "Help action ");
}],
@ "Settings": [WPAttributedStyleAction styledActionWithAction: ^ {
NSLog (@ "Settings action ");
}],
@ "Link": [UIColor orangeColor]};
Self. label1.attributedText = [@ "Attributed Bold Red text" attributedStringWithStyleBook: style1];
Self. label2.attributedText = [@ "[td] Multiple styles text [td]" attributedStringWithStyleBook: style2];
Http://ios.662p.com/thread-2190-1-1.html