Swift 4: Padding of UITextField & UITextView

Sunny, Lee
1 min readMay 12, 2018

--

Step 1: IBDesignable for custom UITextField & UITextView

Extension for Inspectable Corner Radius, Border Color, and Shadow

This is an additional part which isn’t related to padding. If you don’t need to know about this subject, simply jump to step 2.

Step 2: Padding of UITextField & UITextView

1. UITextField Padding

Line 5: Change to whatever padding you like.

Line 12, 16, 21: Override textRect, placeholderRect, editingRect to the padding you’ve implemented.

2. UITextView Padding

Line 4: Set textContainerInset to UIEdgeInsets you need.

Have fun with Swift! Feel free to ask any question :)

--

--

Sunny, Lee
Sunny, Lee

Written by Sunny, Lee

CMU Master of Software Engineering student who loves outdoor activities

Responses (2)