How can I make a clickable link in an NSAttributedString?

Use NSMutableAttributedString. NSMutableAttributedString * str = [[NSMutableAttributedString alloc] initWithString:@”Google”]; [str addAttribute: NSLinkAttributeName value: @”http://www.google.com” range: NSMakeRange(0, str.length)]; yourTextView.attributedText = str; Edit: This is not directly about the question but just to clarify, UITextField and UILabel does not support opening URLs. If you want to use UILabel with links you can check TTTAttributedLabel. Also you should … Read more

Getting and Setting Cursor Position of UITextField and UITextView in Swift

The following content applies to both UITextField and UITextView. Useful information The very beginning of the text field text: let startPosition: UITextPosition = textField.beginningOfDocument The very end of the text field text: let endPosition: UITextPosition = textField.endOfDocument The currently selected range: let selectedRange: UITextRange? = textField.selectedTextRange Get cursor position if let selectedRange = textField.selectedTextRange { … Read more

Placeholder in UITextView

I made a few minor modifications to bcd’s solution to allow for initialization from a Xib file, text wrapping, and to maintain background color. Hopefully it will save others the trouble. UIPlaceHolderTextView.h: #import <Foundation/Foundation.h> IB_DESIGNABLE @interface UIPlaceHolderTextView : UITextView @property (nonatomic, retain) IBInspectable NSString *placeholder; @property (nonatomic, retain) IBInspectable UIColor *placeholderColor; -(void)textChanged:(NSNotification*)notification; @end UIPlaceHolderTextView.m: #import … Read more