Tutorial by Examples

Swift textView.text = "Hello, world!" Objective-C: textView.text = @"Hello, world!";
// Modify some of the attributes of the attributed string. let attributedText = NSMutableAttributedString(attributedString: textView.attributedText!) // Use NSString so the result of rangeOfString is an NSRange. let text = textView.text! as NSString // Find the range of each element to modif...
Swift textView.textAlignment = .left Objective-C textView.textAlignment = NSTextAlignmentLeft;
Responding to Editing Notifications textViewShouldBeginEditing(_:) textViewDidBeginEditing(_:) textViewShouldEndEditing(_:) textViewDidEndEditing(_:) Responding to Text Changes textView(_:shouldChangeTextIn:replacementText:) textViewDidChange(_:) Responding to URL textView(_: UITe...
Swift //System Font textView.font = UIFont.systemFont(ofSize: 12) //Font of your choosing textView.font = UIFont(name: "Font Name", size: 12) Objective-C //System Font textView.font = [UIFont systemFontOfSize:12]; //Font of your choosing textView.font = [UIFont fontWithName:...
Swift textView.textColor = UIColor.red Objective-C textView.textColor = [UIColor redColor];
NSString *htmlString = @"<p> This is an <b>HTML</b> text</p>"; NSAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithData: [htmlString dataUsingEncoding:NSUnicodeStringEncoding] ...
UITextView has built in support to auto detect a variety of data. The data that is able to be auto-detected currently includes: enum { UIDataDetectorTypePhoneNumber = 1 << 0, UIDataDetectorTypeLink = 1 << 1, UIDataDetectorTypeAddress = 1 << 2, UID...
Swift if let text = self.textView.text where !text.isEmpty { // Do stuff for text } else { // Do stuff for nil text or empty string } Objective-C if (self.textView.text.length > 0){ // Do stuff for text } else { // Do stuff for nil text or empty string }
Useful information The very beginning of the text field text: let startPosition: UITextPosition = textView.beginningOfDocument The very end of the text field text: let endPosition: UITextPosition = textView.endOfDocument The currently selected range: let selectedRange: UITextRange? = textV...
UITextView has extra paddings by default. Sometimes it's annoying especially if you want to measure some text without view instance and place them at some area precisely. Do this to remove such paddings. messageTextView.textContainerInset = UIEdgeInsetsZero messageTextView.textContainer.lineFragm...

Page 1 of 1