Last active
February 19, 2021 18:19
-
-
Save karigrooms/040616383d426013a15ca773915bd942 to your computer and use it in GitHub Desktop.
SwiftUI composition order of view modifiers for Lessons in SwiftUI blog post (second example)
This file contains hidden or 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 | |
struct MyButtonStyle: ButtonStyle { | |
func makeBody(configuration: Configuration) -> some View { | |
configuration.label | |
.fixedSize() | |
// apply size modifiers | |
.frame(width: nil, height: 48) | |
.padding(.horizontal, 24) | |
// apply background color AFTER size modifiers | |
.background(Color.blue) | |
.foregroundColor(Color.white) | |
// apply corner radius after everything | |
.cornerRadius(24) | |
} | |
} | |
struct MyButtonStyle_Previews: PreviewProvider { | |
static var previews: some View { | |
Button("Button", action: {}) | |
.buttonStyle(MyButtonStyle()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment