Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I center a placeholder text in a TextField

My code is as follow:

TextField("Enter Your Email", text: self.$username)

How can I make the placeholder "enter your email" be centered in the TextField?

like image 930
Damion Silver Avatar asked Dec 03 '19 06:12

Damion Silver


People also ask

Can you align the text inside the placeholder?

In most of the browsers, placeholder texts are usually aligned in left. The selector uses text-align property to set the text alignment in the placeholder. This selector can change browser to browser.

How do you vertically align placeholder text?

To center it vertically, I multiplied the height of the element to 7.5% and make it line-height. Show activity on this post. Show activity on this post. Use the line-height property to make the placeholder vertically centered.

How do you center text in a field in HTML?

Using the <center></center> tags One way to center text or put it in the middle of the page is to enclose it within <center></center> tags.


2 Answers

 TextField("Enter Your Email", text: self.$username)
        .multilineTextAlignment(TextAlignment.center)
like image 172
Sandeep Maurya Avatar answered Oct 12 '22 22:10

Sandeep Maurya


you can use this code:

 yourtextfield.textAlignment = .center
like image 37
Haya Hashmat Avatar answered Oct 12 '22 23:10

Haya Hashmat