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 ContentView: View { | |
| @State private var currentIndex = 0 | |
| @GestureState private var dragOffset: CGFloat = 0 | |
| let examples = ["1", "2", "3"] | |
| let itemPadding: CGFloat = 20 | |
| var body: some View { | |
| GeometryReader { bodyView in |
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
| struct ContentView: View { | |
| @State private var isTrailing = false | |
| var body: some View { | |
| VStack(alignment: isTrailing ? .trailing : .leading) { | |
| Image(systemName: "box.truck") | |
| .font(.system(size: 64)) | |
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 UIKit | |
| import SwiftUI | |
| struct PageControl: UIViewRepresentable { | |
| var numberPages: Int | |
| @Binding var currentPage: Int | |
| func makeCoordinator() -> Coordinator { | |
| Coordinator(control: self) | |
| } |
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 FeatureCard: View { | |
| var landmark: Landmark | |
| var body: some View { | |
| landmark.featureImage? | |
| .resizable() | |
| .overlay { // overlayで重ねる | |
| TextOverlay(landmark: landmark) |
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 ContentView: View { | |
| @State private var selection: CustomTab = .home | |
| var body: some View { | |
| VStack { | |
| TabView(selection: $selection) { | |
| Text("Home") | |
| .tag(CustomTab.home) |
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
| func image(color: UIColor, size: CGSize) -> UIImage { | |
| let renderer = UIGraphicsImageRenderer(size: size) | |
| return renderer.image(actions: { rendererContext in | |
| // 描画処理 | |
| rendererContext.cgContext.setFillColor(color.cgColor) // 色を指定 | |
| rendererContext.fill(CGRect(origin: CGPoint.zero, size: size)) // 塗りつぶす | |
| }) | |
| } |
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 ContentView: View { | |
| @State private var selection: Tab = .featured | |
| enum Tab { | |
| case featured | |
| case list |
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
| .listRowInsets(EdgeInsets()) |
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
| let names = ["Alice", "Bob", "Charlie", "David", "Eve", "Frank", "Grace", "Harry", "Iris", "Jack"] | |
| let groupedNames = Dictionary(grouping: names) { $0.first! } | |
| print(groupedNames) |
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 Foundation | |
| var landmarks: [Landmark] = load("landmarkData.json") | |
| // 型推論を使用するためジェネリクスでもOK | |
| func load<T: Decodable>(_ filename: String) -> T { | |
| let data: Data | |
| guard let file = Bundle.main.url(forResource: filename, withExtension: nil) | |
| else { |
NewerOlder