Created
December 26, 2019 10:52
-
-
Save DaisukeNagata/e4158a471a0e8d2943d7dcd5e14ba4c5 to your computer and use it in GitHub Desktop.
SwiftUI_CustomView
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 ContentView: View { | |
var body: some View { | |
Text("Hello").modifier(MyModifier(color: .yellow, | |
frameSize: 100, // frmae is size | |
verticalSet: .top, // originY | |
horizontalSet: .trailing, // originX | |
verticalSize: 100, // originY size | |
horizontalSize: 100)) // originX size | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} | |
struct MyModifier: ViewModifier { | |
var color : Color? = nil | |
var frameSize : CGFloat? = nil | |
var verticalSet : Edge.Set? = nil | |
var horizontalSet : Edge.Set? = nil | |
var verticalSize : CGFloat? = nil | |
var horizontalSize: CGFloat? = nil | |
func body(content: Content) -> some View { | |
return content | |
.padding(frameSize ?? 0.0) | |
.background(color) | |
.padding(verticalSet ?? Edge.Set.init(rawValue: 0), verticalSize ?? 0.0) | |
.padding(horizontalSet ?? Edge.Set.init(rawValue: 0), horizontalSize ?? 0.0) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Movie
https://t.co/mX2QABNZFa