Search code examples
watchkitswiftui

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?


Solution

  • Color.init(red: CGFloat, green: CGFloat, blue: CGFloat)
    

    takes a 3 CGFloats with values between 0 and 1

    What you need is…

    Color(red: 255/255, green: 245/255, blue: 158/255)
    

    Note that the .init isn't required in Swift