Create UITextView Programmatically in Swift

In this short Swift code example, you will learn how to create UITextView programmatically in Swift.

  • Create UITextView programmatically
  • Position UITextView at a specific location within a view
  • Position UITextView at the center of the view
  • Change UITextView text color
  • Change UITextView background color
let textView = UITextView(frame: CGRect(x: 20.0, y: 90.0, width: 250.0, height: 100.0))
textView.contentInsetAdjustmentBehavior = .automatic =
textView.textAlignment = NSTextAlignment.justified
textView.textColor =
textView.backgroundColor = UIColor.lightGray

For more Swift code examples and tutorials, please check the Swift Code Examples page on this website.

Leave a Reply

Your email address will not be published.