[Swift] TTTAttributedLabel uses note, tttattributedlabel
Preface
TTTAttributedLabel is inherited from UILabel and can be easily modified based on the existing code. The Star has exceeded 4 K +. I took some notes today.
StatementWelcome to repost, but please keep the original source of the article :) blog Park: http://www.cnblogs.com farmer UNCLE: http://over140.cnblogs.com
Environment
Xcode 6.3.3
Cocoapods 0.37.2
Body
1. If the Pod directly uses TTTAttributedLabel, an error is reported in the Storyboard. error message:
Directly introduce the source code.
2. Add Link
AddLinkToURL (NSURL (string: "https://www.google.com ")!, WithRange: NSString (string: "Welcome to Google"). rangeOfString ("Google "))
Pay attention to the swift syntax. It is not feasible to directly use String. rangeOfString. The NSString method is required.
3. Modify the default link style (Retain text color and underline)
Mainly set linkAttributes
Label. linkAttributes = [kCTForegroundColorAttributeName: agreeLabel. textColor, NSUnderlineStyleAttributeName: NSNumber (long: NSUnderlineStyle. StyleSingle. rawValue)]
Here, the label is TTTAttributedLabel.
References
TTTAttributedLabel for iOS source code reading
TTTAttributedLabel usage