Reputation: 569
I'm using in my app the TextFields component of Google's Material Components library.
As you can see in the following screenshot, the text input is way too close of the leadingView
. How can I add some margin between them?
Here's the code I'm using to create this text field:
emailTextField.translatesAutoresizingMaskIntoConstraints = false
emailTextField.delegate = self
emailTextField.leadingView = UIImageView(image: UIImage(named: "MailIcon"))
emailTextField.leadingViewMode = .always
emailTextFieldController = MDCTextInputControllerUnderline(textInput: emailTextField)
emailTextFieldController?.placeholderText = "Email"
Upvotes: 2
Views: 1926
Reputation: 3149
The underline style text field is not a recommended design anymore. And the original design didn't specify a padding constant for the leading view. Consider changing to the filled controller which has been shown to perform much better in user research studies.
If you have to stick with underline, getting your desired layout is pretty easy.
MaterialComponents
. This could mean you need to run pod update MaterialComponents
if you're using CocoaPods.MDCTextInputControllerUnderline
.leadingViewTrailingPaddingConstant
and return whatever padding you'd like. In Objective-C, this would look like:- (CGFloat)leadingViewTrailingPaddingConstant {
return 16.f;
}
Incidentally, we just pushed the ability to change the clear button's color easily. You can set it to match the underline and text by setting the property textInputClearButtonTintColor
.
Upvotes: 1