Fill a RoundedRectangle with custom color

RoundedRectangle(cornerRadius: 8, style: .continuous) .
foregroundColor(Color.init(red: 255, green: 245, blue: 158))

My rounded rectangle is all white. Why can't I initiate a custom color? Whereas Color.red works perfectly fine?

foregroundColor is the color of the foreground elements…

Namely, the text you type inside.


Are you sure you don't want to set the backgroundColor ?


  var body: some View {
  Group {
  Text("Hello!")
  }
  .background(Color.red)
  }


So:

RoundedRectangle(cornerRadius: 8, style: .continuous) 
.backgroound(Color.init(red: 255, green: 245, blue: 158))


have a look here for more:

https://stackoverflow.com/questions/56437036/swiftui-how-do-i-change-the-background-color-of-a-view

You should use fill().

RoundedRectangle(cornerRadius: 8, style: .continuous)
    .fill(Color(red: 255, green: 245, blue: 158))

Don't use background() for changing the color of RoundedRectangle. It just fills the background of the rounded rectangle rather than the rounded rectangle itself.

Fill a RoundedRectangle with custom color
 
 
Q