Skip to content

Instantly share code, notes, and snippets.

@byJeevan
Last active August 16, 2025 09:35
Show Gist options
  • Select an option

  • Save byJeevan/f67485bf380e86d4f87a723ac383827c to your computer and use it in GitHub Desktop.

Select an option

Save byJeevan/f67485bf380e86d4f87a723ac383827c to your computer and use it in GitHub Desktop.
SwiftUI Components & Extension that saves iOSDev time.
### UIKit is **EVENT-Driven** framework - We could reference each view in the hierarchy, update its appearance when the view is loaded or as a reaction on an event.
### SwiftUI is **Declarative, State Driven** framework - We cannot reference any view in the hierarchy, neither can we directly mutate a view as a reaction to an event.
Instead, we mutate the state bound to the view. Delegates, target-actions, responder chain, KVO .. replaced with Closures & bindings.
@byJeevan
Copy link
Author

To make fullscreen view to fill entire screen:

ZStack {
   Text("Hello").background(.yellow)
}
.frame(maxWidth: .infinity, maxHeight: .infinity) // this is important
.background(.blue)

@byJeevan
Copy link
Author

byJeevan commented Mar 7, 2025

public extension View {

  // Creates a outline border for text of having any font size.
  func outlinedText(shadowColor: Color = .white, radius: CGFloat = 0, offset: CGFloat = 0.5) -> some View {
    self
      .shadow(color: shadowColor, radius: radius, x: offset, y: 0)  // Right
      .shadow(color: shadowColor, radius: radius, x: 0, y: offset)  // Down
      .shadow(color: shadowColor, radius: radius, x: -offset, y: 0) // Left
      .shadow(color: shadowColor, radius: radius, x: 0, y: -offset) // Up
  }
}

@byJeevan
Copy link
Author

byJeevan commented Aug 16, 2025

Create Alert (system alert)

struct ContentView: View {
    @State private var showAlert = false // 1
    
    var body: some View {
        VStack {
            Button("Show Alert") {
                showAlert = true // 2
            }
        }
// 3.
        .alert("Important Message", isPresented: $showAlert) {
            Button("OK", role: .cancel) { }
            Button("Delete", role: .destructive) {
                // handle delete action
            }
        } message: {
            Text("This is an alert in SwiftUI.")
        }
    }
}

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