Last active
February 19, 2021 18:19
-
-
Save karigrooms/02a434001f8248d6426d2f93c12c9d95 to your computer and use it in GitHub Desktop.
SwiftUI composition order of view modifiers for Lessons in SwiftUI blog post (first example)
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 | |
struct MyButtonStyle: ButtonStyle { | |
func makeBody(configuration: Configuration) -> some View { | |
configuration.label | |
.fixedSize() | |
// apply background color BEFORE size modifiers | |
.background(Color.blue) | |
.foregroundColor(Color.white) | |
// apply size modifiers | |
.frame(width: nil, height: 48) | |
.padding(.horizontal, 24) | |
// 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