|
Hey everyone! I'm trying to learn SwiftUI but i've stumbled across a problem related to padding inside an element. So, when i add ".padding()" to one of those elements, instead of giving the text more room, it gives padding to the outside area... How can i increase the space inside of a button/textfield? |
|
|
|
You can do the above for the
For the
If you are re using this button style in lots of place you might want to do a new file called "PaddedButtonStyle" then put this in it
Now you can add it to your button like this and everywhere you want the same button style
I have give it parameter so you can change colors and radius but have the default same as you gave. |
|
Thanks for the help guys. Unfortunately the TextField still appears like the example i showed on the first post... Another question, when i was searching for a solution for this, i saw some results that simply put a "padding" on the TextField and it worked. Was it because all of the examples i saw were made for iOS and i'm doing for macOS? They behave differently? |
|
So i inserted your suggestions for the Button and TextField and it still appears like in the image below. The box around the placeholder text on the TextField is still the same it only added padding around it like i had before and the Button added some horizontal padding but like you see on the image it has some kind of "hidden" padding that's not affecting the height of the button. |
|
|
|
Actually, try adding
|
|
Thanks, it worked! I found a solution for the texfield too, using:
Here's an image of the result:
But it's quiet strange that it's way easier to do this kind of things in an iOS project compared to a macOS one. |
|
SPONSORED From March 20th to 26th, you can join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer!
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.