UITextView that expands to text using auto layout

Summary: Disable scrolling of your text view, and don’t constraint its height. To do this programmatically, put the following code in viewDidLoad: let textView = UITextView(frame: .zero, textContainer: nil) textView.backgroundColor = .yellow // visual debugging textView.isScrollEnabled = false // causes expanding height view.addSubview(textView) // Auto Layout textView.translatesAutoresizingMaskIntoConstraints = false let safeArea = view.safeAreaLayoutGuide NSLayoutConstraint.activate([ textView.topAnchor.constraint(equalTo: … Read more

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

Change UITextField and UITextView Cursor / Caret Color

If you’re targeting iOS 7+, this has been made much easier. Simply change the tintColor of the field with a cursor using the appearance proxy and it will apply throughout the app: Swift 3.0: UITextField.appearance().tintColor = .black Objective-C: [[UITextField appearance] setTintColor:[UIColor blackColor]]; Same answer applies for an individual UITextField: Swift 3.0: myTextField.tintColor = .black Objective-C … Read more

After upgrading to Xcode 11.2 from Xcode 11.1, app crashes due to _UITextLayoutView

Update: Fixed! 🎉🎊 The ONLY Solution is to update This bug is fixed in Xcode 11.2.1. So you can download and use it from here. Storyboards containing a UITextView will no longer cause the app to crash on operating system versions earlier than iOS 13.2, tvOS 13.2, or macOS 10.15.2. (56808566, 56873523) Xcode 11.2 is … Read more

Add placeholder text inside UITextView in Swift?

Updated for Swift 4 UITextView doesn’t inherently have a placeholder property so you’d have to create and manipulate one programmatically using UITextViewDelegate methods. I recommend using either solution #1 or #2 below depending on the desired behavior. Note: For either solution, add UITextViewDelegate to the class and set textView.delegate = self to use the text … Read more

How to dismiss keyboard for UITextView with return key?

Figured I would post the snippet right here instead: Make sure you declare support for the UITextViewDelegate protocol. – (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { if([text isEqualToString:@”\n”]) { [textView resignFirstResponder]; return NO; } return YES; } Swift 4.0 update: func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { if text == … Read more

Multiple lines of text in UILabel

Set the line break mode to word-wrapping and the number of lines to 0: // Swift textLabel.lineBreakMode = .byWordWrapping textLabel.numberOfLines = 0 // Objective-C textLabel.lineBreakMode = NSLineBreakByWordWrapping; textLabel.numberOfLines = 0; // C# (Xamarin.iOS) textLabel.LineBreakMode = UILineBreakMode.WordWrap; textLabel.Lines = 0; Restored old answer (for reference and devs willing to support iOS below 6.0): textLabel.lineBreakMode = UILineBreakModeWordWrap; … Read more

How do I size a UITextView to its content?

This works for both iOS 6.1 and iOS 7: – (void)textViewDidChange:(UITextView *)textView { CGFloat fixedWidth = textView.frame.size.width; CGSize newSize = [textView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)]; CGRect newFrame = textView.frame; newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height); textView.frame = newFrame; } Or in Swift (Works with Swift 4.1 in iOS 11) let fixedWidth = textView.frame.size.width let newSize = textView.sizeThatFits(CGSize(width: fixedWidth, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)