2

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.

pbodsk
  • 6,787
  • 3
  • 21
  • 51
  • You might need to embed your `Text` in another view where you'd apply the background color and the corners. See https://stackoverflow.com/a/67417410/1801544 ? – Larme May 27 '23 at 07:57
  • 1
    try this: `Text(newData3).padding(10).....`, that is, put the `.padding(10)` before the other modifiers, specifically before the `.background(...)` – workingdog support Ukraine May 27 '23 at 08:00

1 Answers1

1

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

Text(newData3).padding(10)
....