Skip to content

Instantly share code, notes, and snippets.

@DaisukeNagata
Created December 26, 2019 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaisukeNagata/e4158a471a0e8d2943d7dcd5e14ba4c5 to your computer and use it in GitHub Desktop.
Save DaisukeNagata/e4158a471a0e8d2943d7dcd5e14ba4c5 to your computer and use it in GitHub Desktop.
SwiftUI_CustomView
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)
}
}
@DaisukeNagata
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment