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
// | |
// ContentView.swift | |
// Emoji Animation hero picker | |
// | |
// Created by Moussa on 3/4/2024. | |
// | |
import SwiftUI | |
struct ContentView: View { |
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
// | |
// CDView.swift | |
// CD | |
// | |
// Created by Daniel Kuntz on 7/3/23. | |
// | |
import SwiftUI | |
struct ShapeWithHole: Shape { |
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
struct ContentView: View { | |
@State private var sliderValue: Double = 0.0 | |
@State private var selectedIndex: Int = -1 | |
@State private var remainder: Double = 0.0 | |
var body: some View { | |
VStack { | |
HStack { | |
ForEach(0..<5) { index in | |
ZStack { | |
Image(systemName: "star.fill") |
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
// Implementation of the view using AppKit. | |
#if os(macOS) | |
import AppKit | |
import SwiftUI | |
final class AppKitTextView: NSView { | |
let textView: NSTextView = { | |
let this = NSTextView() | |
this.translatesAutoresizingMaskIntoConstraints = false | |
return this |
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 Foundation | |
// Here's a pretty typical scenario where you want to encode a polymorphic type - | |
// in this case a Shape type that can be either a Square or Circle. Swift provides | |
// a nice pattern for doing this in a type-safe way using enums: | |
struct Circle: Codable { | |
var radius: Int | |
} |
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
extension View { | |
func minimumPadding(edges: Edge.Set = .all, _ length: CGFloat = 8) -> some View { | |
GeometryReader { geo in | |
padding(.bottom, edges.contains(.bottom) ? max(length, geo.safeAreaInsets.bottom) : 0) | |
.padding(.top, edges.contains(.top) ? max(length, geo.safeAreaInsets.top) : 0) | |
.padding(.leading, edges.contains(.leading) ? max(length, geo.safeAreaInsets.leading) : 0) | |
.padding(.trailing, edges.contains(.trailing) ? max(length, geo.safeAreaInsets.trailing) : 0) | |
.ignoresSafeArea(edges: edges) | |
} | |
} |
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
class ViewController: UIViewController { | |
let left = ScrollViewController() | |
let right = ScrollViewController() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
for child in [left, right] { | |
addChild(child) |
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 | |
/// A wrapper view that provides a mutable Binding to its content closure. | |
/// | |
/// Useful in Xcode Previews for interactive previews of views that take a Binding. | |
struct Stateful<Value, Content: View>: View { | |
var content: (Binding<Value>) -> Content | |
@State private var state: Value | |
init(initialState: Value, @ViewBuilder content: @escaping (Binding<Value>) -> Content) { |
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
#if DEBUG | |
/* | |
This fixes SwiftUI previews not rendering translucent materials correctly by | |
swizzling a couple of properties on NSWindow. | |
Just drop into your project and add to the target being previewed (or something it links against). | |
Notice the #if DEBUG, so this code won't end up in release builds. It also checks for the | |
XCODE_RUNNING_FOR_PREVIEWS environment variable so that it won't affect regular debug builds of the app. |
NewerOlder