Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add spacing between text and background colour in a Swift text box?

Tags:

swift

swiftui

I have a text box in Swift with a background colour applied. However, the background covers some of the text as seen here

I want there to be some space between the text and the border of the background colour.

Here is my current code

Text(newData3)
    .foregroundColor(.gray)
    .frame(maxWidth: .infinity, alignment: .leading)
    .background(Color.yellow).frame(width: 400, alignment: .center)
    .cornerRadius(30)
    .padding(10)

I'm new to Swift so I'm not sure what to try. Any help would be much appreciated.

like image 896
James Farmer Avatar asked Oct 15 '25 02:10

James Farmer


1 Answers

Try this approach of adding the .padding(10) before the other modifiers, specifically before the .background(...), like this:

Text(newData3).padding(10)
.... 
like image 124
workingdog support Ukraine Avatar answered Oct 17 '25 17:10

workingdog support Ukraine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!