Skip to content

Instantly share code, notes, and snippets.

@kipsong133
Created March 8, 2024 09:17
Show Gist options
  • Save kipsong133/50525b5a78b779c0150d13d137053e5f to your computer and use it in GitHub Desktop.
Save kipsong133/50525b5a78b779c0150d13d137053e5f to your computer and use it in GitHub Desktop.
[SwiftUI][Modifier]List Background color change #SwiftUI
import SwiftUI
/// 예제
/// List { ... }
/// .modifier(ListBackgroundModifier())
/// .background(Color.red) // 원하는 색상 적용
struct ListBackgroundModifier: ViewModifier {
@ViewBuilder
func body(content: Content) -> some View {
if #available(iOS 16.0, *) {
content
.scrollContentBackground(.hidden)
} else {
content
}
}
}
// 다른 해결방법
//struct Example: View {
// ...
// init() {
// UICollectionView.appearance().backgroundColor = .clear
// }
//}
//
//
//extension UICollectionReusableView {
// override open var backgroundColor: UIColor? {
// get { .clear }
// set { }
// // default separators use same color as background
// // so to have it same but new (say red) it can be
// // used as below, otherwise we just need custom separators
// //
// // set { super.backgroundColor = .red }
// }
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment