Ich muss einige tapGestures zu einem Teil eines Textes hinzufügen, das ist in einem UILabel. Es scheint in der Lage zu sein, einen Hyperlink zu erstellen - ich denke also, es ist auch möglich, einen Funktionsaufruf zu machen, aber ich bin mir nicht sicher, wie ich das machen soll.Wie Funktion-Aufruf (nicht Hyperlink) zu einem Teil eines NSAttributedString in einem UILabel hinzufügen?
Heres mein Code:
let regularFont = UIFont(name: Constants.robotoRegular, size: 13)!
let att1 = [NSFontAttributeName: regularFont]
let turqoiseFont = UIFont(name: Constants.robotoBold, size: 13)!
let att2 = [NSFontAttributeName: turqoiseFont]
let attString1 = NSMutableAttributedString(string: "By creating a profile, I accept ", attributes: att1)
attString1.addAttribute(NSForegroundColorAttributeName, value: UIColor.darkGrayColor(), range: NSMakeRange(0, attString1.length))
let attString2 = NSMutableAttributedString(string: "Terms and Conditions ", attributes: att2)
attString2.addAttribute(NSForegroundColorAttributeName, value: Colors.loginButtonColor, range: NSMakeRange(0, attString2.length))
let attString3 = NSMutableAttributedString(string: "and ", attributes: att1)
attString3.addAttribute(NSForegroundColorAttributeName, value: UIColor.darkGrayColor(), range: NSMakeRange(0, attString3.length))
let attString4 = NSMutableAttributedString(string: "Private Policy.", attributes: att2)
attString4.addAttribute(NSForegroundColorAttributeName, value: Colors.loginButtonColor, range: NSMakeRange(0, attString4.length))
let index = "\(attString1.string.endIndex)"
attString1.insertAttributedString(attString4, atIndex: Int(index)!)
attString1.insertAttributedString(attString3, atIndex: Int(index)!)
attString1.insertAttributedString(attString2, atIndex: Int(index)!)
termsAndConditionLabel.attributedText = attString1
Ich möchte die türkisfarbene Teile entweder auf Vertragsbedingungen für die Benutzer zu übernehmen zu können, oder Privat-Politik. Kann mir bitte jemand bei diesem Problem helfen? :))
Super! Ich habe deine Lösung benutzt, mit ein bisschen Feinschliff - und jetzt funktioniert es wie ein Zauber! Danke vielmals –