Created
June 23, 2016 15:42
-
-
Save Qw4z1/bfdbfd73055d41bf71bf8f4a30a76984 to your computer and use it in GitHub Desktop.
ZSWTappableLabel bug
This file contains hidden or 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
func betterLabel() -> ZSWTappableLabel { | |
let participantsLabel:ZSWTappableLabel = ZSWTappableLabel(frame: CGRect(x: 10, y: 5, width: self.view.bounds.size.width * 0.75, height: 43)) | |
var par2 = participants | |
for i in 1...6 { | |
par2.append(User(id: "Dummy", name: "Test User")) | |
} | |
func userWrapWrap(user: User) -> String { | |
return String(format: "<link id=%@>%@</link>", | |
user.userId!, ZSWEscapedStringForString(user.name!.uppercaseString)) | |
} | |
let baseText = NSMutableString(string: "PARTICIPANTS:\n") | |
for (index, p) in par2.enumerate() { | |
if index != 0 { | |
baseText.appendString(", ") | |
} | |
baseText.appendString(userWrapWrap(p)) | |
} | |
let options = ZSWTaggedStringOptions() | |
options["link"] = .Dynamic({ tagName, tagAttributes, stringAttributes in | |
guard let typeString = tagAttributes["id"] as? String else { | |
return [String: AnyObject]() | |
} | |
let userId = typeString | |
return [NSFontAttributeName: UIFont(name: Constants.mainFontName, size: 17)!, | |
ZSWTappableLabelTappableRegionAttributeName: true, | |
NSForegroundColorAttributeName: UIColor.gtt_mainColor(), | |
ZSWTappableLabelHighlightedBackgroundAttributeName: UIColor.gtt_mainColor(), | |
ZSWTappableLabelHighlightedForegroundAttributeName: UIColor.gtt_mainColor(), | |
ChatController.UserIdAttributeName: userId | |
] | |
}) | |
participantsLabel.tapDelegate = self | |
participantsLabel.font = UIFont(name: Constants.mainFontName, size: 17) | |
participantsLabel.numberOfLines = 0 | |
participantsLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping | |
participantsLabel.attributedText = try? ZSWTaggedString(string: baseText as String).attributedStringWithOptions(options) | |
// Calling size to fit to expand label if needed/ | |
participantsLabel.sizeToFit() | |
return participantsLabel | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment