HomeiOS Developmentios - Find out how to decide textual content shade primarily based...

ios – Find out how to decide textual content shade primarily based on background picture?


I am enjoying round with photographs in SwiftUI by making a easy e-book cowl view.

VStack {
    AsyncImage(url: URL(string: coverURL)) { section in
        swap section {
        case .failure:
            Picture(systemName: "photograph")
                .font(.largeTitle)
        case .success(let picture):
            picture.resizable()
        default:
            ProgressView()
        }
    }
    .scaledToFit()
    .body(peak: 300)
    .cornerRadius(10)
    .padding()

    VStack {
        Textual content(title)
            .font(.title)
            .foregroundStyle(.white)

        if let creator = creator {
            Textual content(creator)
                .font(.subheadline)
                .foregroundStyle(.white)
        }
    }
    .padding()

}
.padding(.prime, geometry.safeAreaInsets.prime)
.body(maxWidth: .infinity)
.background(
    AsyncImage(url: URL(string: coverURL)) { section in
        swap section {
        case .failure:
            Colour.grey
        case .success(let picture):
            picture.resizable()
        default:
            Colour.grey
        }
    }
        .blur(radius: 30, opaque: true)
)

The issue is that the textual content would not distinction sufficient when the picture is gentle. Ideally the textual content must be both white or black relying on the background picture. I’ve discovered strategies to calculate the common shade of a picture and base the textual content’s shade on that, however these work for UIImage not Picture. Mix mode, .blendMode(.distinction), additionally did not produce the most effective outcomes.

How can I alter textual content (title and creator on this instance) shade primarily based on their background picture in SwiftUI?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments