|
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? |
|
I think this is what you want:
|
|
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. |
|
Yeah, that's weird. I get the same thing when I try the code for macOS instead of iOS. I thought they were supposed to behave the same but that doesn't seem to be the case. I haven't done anything with macOS yet. It seems like I can modify the width of the button but not the height. |
|
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 Ready to dive into the world of Swift? try! Swift Tokyo is the premier iOS developer conference will be happened in April 9th-11th, where you can learn from industry experts, connect with fellow developers, and explore the latest in Swift and iOS development. Don’t miss out on this opportunity to level up your skills and be part of the Swift community!
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.