Skip to content

Instantly share code, notes, and snippets.

View SuperEllipse.swift
// Created by satoutakeshi on 2021/01/30 in MIT License
//
import SwiftUI
struct SuperEllipse: View {
var body: some View {
Image(systemName: "moon")
.resizable()
.frame(width: 100, height: 100)
@SatoTakeshiX
SatoTakeshiX / SwithcMenu.swift
Last active Jan 23, 2021
開閉式メニュー
View SwithcMenu.swift
//
// ContentView.swift
// MenuSample
//
// Created by satoutakeshi on 2020/12/21.
//
import SwiftUI
struct ContentView: View {
View Content.swift
final class DataSource: ObservableObject {
@Published var counter = 0
}
struct StateObjectCounterView: View {
@StateObject private var dataSource = DataSource()
var body: some View {
VStack {
Button("increment counter") {
dataSource.counter += 1
View merge.rb
master_array = [[1, 2], [3, 4]]
remote_array = [{"id" => 12, "config" => [3, 4]}, {"id" => 533, "config" => [1, 2]}]
result_test = ["a", "b"] # master_arrayと同じindexでオブジェクトを作りたい。 { "config" : [1, 2], "id":"a"}
array_result = master_array.map.with_index { |item, index|
remote = remote_array.find {|i| item == i["config"]}
result = {
"result" => result_test[index],
"configs" => item,
"id" => remote["id"]
@SatoTakeshiX
SatoTakeshiX / SingleSelectableView.swift
Last active Jul 12, 2020
SingleSelectableView.swift
View SingleSelectableView.swift
enum BoxType: String {
case unknown
case red
case green
case blue
}
final class SingleSelectableBoxViewModel: ObservableObject {
@Published var selectedBox: BoxType = .unknown
var cancels: [AnyCancellable] = []
@SatoTakeshiX
SatoTakeshiX / MultipleSelectableView.swift
Created Jul 12, 2020
SwiftUI Multiple Selectable View Components
View MultipleSelectableView.swift
import SwiftUI
import Combine
final class MultipleSelectableViewModel: ObservableObject {
@Published var isSelectedRed: Bool = false
@Published var isSelectedGreen: Bool = false
@Published var isSelectedBlue: Bool = false
var cancels: [Cancellable] = []
@SatoTakeshiX
SatoTakeshiX / ContentView.swift
Last active Jun 14, 2020
AVFundation by SwiftUI with Coordinator.
View ContentView.swift
struct ErrorInfo: Error {
var showError: Bool
var message: String
}
struct ContentView: View {
@State var errorInfo: ErrorInfo = ErrorInfo(showError: false, message: "")
@State var onAppear: Bool = false
var body: some View {
ZStack {
View scaleAndOrient.swift
func scaleAndOrient(image: UIImage) -> UIImage {
// Set a default value for limiting image size.
let maxResolution: CGFloat = 640
guard let cgImage = image.cgImage else {
print("UIImage has no CGImage backing it!")
return image
}
View ContentView.swift
struct ContentView: View {
var body: some View {
NavigationView {
NavigationLink(destination: Text("sdetail")) {
Text("master")
.navigationBarTitle("nav", displayMode: .inline)
}
.navigationBarTitle("nav", displayMode: .large)
Text("detassssssil")
@SatoTakeshiX
SatoTakeshiX / CodePiece.swift
Created Dec 23, 2019
SwiftUIのButtonのタップ領域を広げるにはViewの方をpaddingする #CodePiece #SwiftUI
View CodePiece.swift
Button(action: doSomething) {
Text("Default padding")
.padding()
.background(Color.yellow)
}