Created
March 8, 2024 09:17
-
-
Save kipsong133/50525b5a78b779c0150d13d137053e5f to your computer and use it in GitHub Desktop.
[SwiftUI][Modifier]List Background color change #SwiftUI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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