Skip to content

How to chager url and update image in swiftUI #1979

Answered by onevcat
hoangnam714 asked this question in Q&A
Discussion options

You must be logged in to vote

Here is a sample running well when changing the URL (or URL string):

struct SingleViewDemo : View {
    @State var string = "kingfisher-1.jpg"
    var body: some View {
        KFImage(
            URL(string: "https://raw.githubusercontent.com/onevcat/Kingfisher-TestImages/master/DemoAppImage/Loading/\(string)")
        )
        Button(action: {
            string = "kingfisher-2.jpg"
        }) { Text("Next Image") }
    }
}

Any luck to try this code and see if that works? If so, maybe you are having a wrong url in your Button action?

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by hoangnam714
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants