0

I have added the Glow colour to text with the help of shadow using custom class code below in SwiftUI.

Want to achieve:-

ScreenShot

Output:-

ScreenShot

Code:-

struct ContentView: View {
var body: some View {
    ZStack {
        Text("Hello world!")
            .underline()
            .font(Font.system(size: 26))
            .padding(.bottom, 80).shadow(color: Color(UIColor(displayP3Red: 96/255, green: 252/255, blue: 255/255, alpha: 2)), radius: 3, x: 1, y: 1)
      }
   }
}

Question: Can someone please explain to me how to set same glow colour on text, I've tried with above code but no results yet.

Can someone please explain to me How to get Progress?

Any help would be greatly appreciated.

Thanks in advance.

Sham Dhiman
  • 1,348
  • 1
  • 21
  • 59
  • 2
    Does this answer your question https://stackoverflow.com/a/70661774/12299030? – Asperi Jan 21 '22 at 07:47
  • @Asperi, but i want custom class means which i only set the text, colour code and font size. But you can check both design are different on glow effect not match with each other. Could you please help me how to create same glow effect. – Sham Dhiman Jan 21 '22 at 17:24
  • Check out that link that Asperi sent -- it looks like exactly what you need. In terms of your question, it's unclear what a "custom class" has to do with this. You don't have any "custom class" in your code. – jnpdx Jan 21 '22 at 19:13

1 Answers1

1

Try this:-

struct CustomLabelModify: View {

var body: some View {
    ZStack{
        Color.black
        Group{
            Text("Following")
                .addGlowEffect(color1: Color(Color.RGBColorSpace.sRGB, red: 96/255, green: 252/255, blue: 255/255, opacity: 1), color2: Color(Color.RGBColorSpace.sRGB, red: 44/255, green: 158/255, blue: 238/255, opacity: 1), color3: Color(Color.RGBColorSpace.sRGB, red: 0/255, green: 129/255, blue: 255/255, opacity: 1))
          }
       }
    }
 }


extension View {
func addGlowEffect(color1:Color, color2:Color, color3:Color) -> some View {
    self
        .foregroundColor(Color(hue: 0.5, saturation: 0.8, brightness: 1))
        .background {
            self
                .foregroundColor(color1).blur(radius: 0).brightness(0.8)
        }
        .background {
            self
                .foregroundColor(color2).blur(radius: 4).brightness(0.35)
        }
        .background {
            self
                .foregroundColor(color3).blur(radius: 2).brightness(0.35)
        }
        .background {
            self
                .foregroundColor(color3).blur(radius: 12).brightness(0.35)
            
        }
     }
  }
Sham Dhiman
  • 1,348
  • 1
  • 21
  • 59