Skip to content

Instantly share code, notes, and snippets.

@qoli
Created December 30, 2023 08:51
Show Gist options
  • Save qoli/fc7e0723276aa14e7aed701b78056616 to your computer and use it in GitHub Desktop.
Save qoli/fc7e0723276aa14e7aed701b78056616 to your computer and use it in GitHub Desktop.
//
// ScrollView.swift
// SyncNext
//
// Created by 黃佁媛 on 2023/9/25.
//
import Foundation
import SwiftUI
extension View {
func fadeOutHorizontal(fadeLength: CGFloat = 50) -> some View {
return mask(
HStack(spacing: 0) {
// Top gradient
LinearGradient(gradient:
Gradient(
colors: [Color.black.opacity(0), Color.black]),
startPoint: .leading, endPoint: .trailing
)
.frame(width: fadeLength)
Rectangle().fill(Color.black)
// bottom gradient
LinearGradient(gradient:
Gradient(
colors: [Color.black.opacity(0), Color.black]),
startPoint: .trailing, endPoint: .leading
)
.frame(width: fadeLength)
}
)
}
func fadeOutVertical(fadeLength: CGFloat = 50) -> some View {
return mask(
VStack(spacing: 0) {
// Top gradient
LinearGradient(gradient:
Gradient(
colors: [Color.black.opacity(0), Color.black]),
startPoint: .top, endPoint: .bottom
)
.frame(height: fadeLength)
Rectangle().fill(Color.black)
// bottom gradient
LinearGradient(gradient:
Gradient(
colors: [Color.black.opacity(0), Color.black]),
startPoint: .bottom, endPoint: .top
)
.frame(height: fadeLength)
}
)
}
func fadeOutTop(fadeLength: CGFloat = 50) -> some View {
return mask(
VStack(spacing: 0) {
// Top gradient
LinearGradient(gradient:
Gradient(
colors: [Color.black.opacity(0), Color.black]),
startPoint: .top, endPoint: .bottom
)
.frame(height: fadeLength)
Rectangle().fill(Color.black)
}
)
}
func fadeOutBottom(fadeLength: CGFloat = 50) -> some View {
return mask(
VStack(spacing: 0) {
Rectangle().fill(Color.black)
// bottom gradient
LinearGradient(gradient:
Gradient(
colors: [Color.black.opacity(0), Color.black]),
startPoint: .bottom, endPoint: .top
)
.frame(height: fadeLength)
}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment