Gradient as foreground color of Text in SwiftUI

后端 未结 6 1081
终归单人心
终归单人心 2021-02-08 12:55

Is there any way of using a gradient as foregroundColor of Text in SwiftUI?

Thanks for the answers in advance!

6条回答
  •  -上瘾入骨i
    2021-02-08 13:12

    You can use this to have gradient as foreground color of your Text:

    Text("Hello World")
                    .padding()
                    .foregroundColor(.white)
                    .background(LinearGradient(gradient: Gradient(colors: [.white, .black]), startPoint: .top, endPoint: .bottom))
    

    Hope this helps :) you can also use this link for your reference: https://www.hackingwithswift.com/quick-start/swiftui/how-to-render-a-gradient

提交回复
热议问题