Skip to content

Instantly share code, notes, and snippets.

Avatar

Kaname Noto notoroid

View GitHub Profile
View 06_settings-bundle-app-storage.swift
struct ContentView: View {
@AppStorage(wrappedValue: false, "enabled_preference") var enabled_preference
var body: some View {
NavigationView {
Text("The toolbar is displayed in conjunction with the switch On/Off in the Settings application - Third Party Application Settings - Sample Application Settings.\n\nNote: The AppStorage value will revert to its initial value after each app transfer after the build, so build carefully.")
.padding()
.toolbar {
ToolbarItemGroup(placement: .bottomBar) {
if enabled_preference {
Spacer()
@notoroid
notoroid / 05_mechanical-arm.swift
Created Feb 14, 2021
Sample of using SwifUI's rotationEffect modifier.
View 05_mechanical-arm.swift
import SwiftUI
enum MechanicalArm {
static let colors: [Color] = [Color(UIColor(red: 0.349, green: 0.671, blue: 0.914, alpha: 1.000)) /*.red, .green, .yellow, .blue, .yellow*/]
static let manipulatorJointEdge = CGFloat(16.5); static let manipulatorRootEdge = CGFloat(37.5)
static let manipulatorWidth = CGFloat(9); static let manipulatorFirstLength = CGFloat(60); static let manipulatorOtherLength = CGFloat(37.5)
static let armLength = CGFloat(105); static let armWidth = CGFloat(37.5); static let armJointEdge = CGFloat(16.5)
static let standWidth = CGFloat(75); static let standHeighth = CGFloat(60)
static let defaultArmAngle = Double(0); static let defaultWristAngle = Double(-45); static let defaultFingerAngle = Double(40)
}
View 04_curved-tabbar.swift
import SwiftUI
struct TopFrameView: Shape {
func path(in rect: CGRect) -> Path {
let bezierPath = UIBezierPath()
bezierPath.move(to: CGPoint(x: 9.16, y: 0.04))
let curvePoints = [(CGPoint(x: 22.13, y: 1.8), CGPoint(x: 13.75, y: 0.17), CGPoint(x: 18.98, y: 0.6)), (CGPoint(x: 36.89, y: 10.14), CGPoint(x: 28.69, y: 4.3), CGPoint(x: 31.15, y: 4.93)), (CGPoint(x: 46.73, y: 22.65), CGPoint(x: 42.63, y: 15.35), CGPoint(x: 44.27, y: 18.48)), (CGPoint(x: 58.2, y: 34.32), CGPoint(x: 49.19, y: 26.81), CGPoint(x: 52.47, y: 30.78)), (CGPoint(x: 70.5, y: 37.65), CGPoint(x: 63.94, y: 37.86), CGPoint(x: 70.5, y: 37.65)), (CGPoint(x: 82.8, y: 34.32), CGPoint(x: 70.5, y: 37.65), CGPoint(x: 77.06, y: 37.86)), (CGPoint(x: 94.27, y: 22.65), CGPoint(x: 88.53, y: 30.78), CGPoint(x: 91.81, y: 26.81)), (CGPoint(x: 104.11, y: 10.14), CGPoint(x: 96.73, y: 18.48), CGPoint(x: 98.37, y: 15.35)), (CGPoint(x: 118.87, y: 1.8), CGPoint(x: 109.85, y: 4.93), CGPoint(x: 112.31, y: 4.3)), (CGPoint(x: 140.79, y: 0.12)
@notoroid
notoroid / 03_motion-tabbar.swift
Last active Jan 14, 2021
Building a Beautiful Animated Motion Tab Bar Widget With SwiftUI.
View 03_motion-tabbar.swift
import SwiftUI
struct TopFrameView: Shape {
func path(in rect: CGRect) -> Path {
let bezierPath = UIBezierPath()
bezierPath.move(to: CGPoint(x: 53.22, y: 4.36))
for (to, controlPoint1, controlPoint2) in [(CGPoint(x: 60.83, y: 13.06), CGPoint(x: 57.76, y: 7.77), CGPoint(x: 60.14, y: 11.68)), (CGPoint(x: 68.43, y: 22.84), CGPoint(x: 63, y: 17.4), CGPoint(x: 65.05, y: 20.96)), (CGPoint(x: 75.16, y: 23.98), CGPoint(x: 70.49, y: 23.98), CGPoint(x: 75.16, y: 23.98))] {
bezierPath.addCurve(to: to, controlPoint1: controlPoint1, controlPoint2: controlPoint2)
}
bezierPath.addLine(to: CGPoint(x: 0.84, y: 23.98))
@notoroid
notoroid / 02_ArchiveBench.swift
Created Jan 3, 2021
Apple M1 chip archive benchmark for macOS app
View 02_ArchiveBench.swift
import SwiftUI
import Combine
import AppleArchive
import System
enum ArchiveBenchResult {
case failureError(error: Error)
case notExistsSourceFile
case notOpenReadFileStream
case notOpenWriteFileStream
@notoroid
notoroid / 01_sf-symbols-sample.swift
Last active Dec 30, 2020
SFSymbolsSample for SwiftUI
View 01_sf-symbols-sample.swift
import SwiftUI
import DeviceGuru
enum DeviceStyleIcon: String {
case phoneHome = "phh" // iPhone and iPod touch devices with homebutton
case phone = "ph" // iPhone
case padHome = "pah" // iPad witn homebutton
case pad = "pa" // iPad
case none = "n" // none (AppleWatch, appleTV, mac)
}