Created
March 16, 2020 15:37
-
-
Save naveedmcs/57ab03d2358f81664bbe862249cd100a to your computer and use it in GitHub Desktop.
HyperLink
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
| //call this method in view didload | |
| self.hyperLinkSetup() | |
| func hyperLinkSetup() { | |
| let string = "Agree to our Terms & Conditions and Privacy Policy" | |
| let attributedString = NSMutableAttributedString(string: string) | |
| attributedString.addAttribute(.link, value: ApiBaseManager.hyperLinks.terms , range: (string as NSString).range(of: "Terms & Conditions")) | |
| attributedString.addAttribute(.link, value: ApiBaseManager.hyperLinks.privacy , range: (string as NSString).range(of: "Privacy Policy")) | |
| attributedString.setFont(UIFont.systemFont(ofSize: 18)) | |
| attributedString.setColor(.white) | |
| termsAndContitionTextView.attributedText = attributedString | |
| } | |
| @IBAction func agrreementBtnTapped(sender: UIButton) { | |
| self.termsAndConditionBtn.isSelected.toggle() | |
| } | |
| } | |
| extension RegisterVC: UITextViewDelegate { | |
| func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool { | |
| UIApplication.shared.open(URL) | |
| return false | |
| } | |
| } | |
| extension NSMutableAttributedString { | |
| @discardableResult | |
| func setFont(_ font: UIFont, range: NSRange? = nil)-> NSMutableAttributedString { | |
| let range = range ?? NSMakeRange(0, self.length) | |
| self.addAttributes([.font: font], range: range) | |
| return self | |
| } | |
| @discardableResult | |
| func setColor(_ color: UIColor, range: NSRange? = nil)-> NSMutableAttributedString { | |
| let range = range ?? NSMakeRange(0, self.length) | |
| self.addAttributes([.foregroundColor: color], range: range) | |
| return self | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment