Skip to content

Instantly share code, notes, and snippets.

View gabrieltheodoropoulos's full-sized avatar

Gabriel Theodoropoulos gabrieltheodoropoulos

View GitHub Profile
@gabrieltheodoropoulos
gabrieltheodoropoulos / AlterImageButton.swift
Created November 5, 2020 15:12
SwiftUI button implementation with image that is changed on press, without default highlighting
Image(!isPressed ? "imageNormal" : "imagePressed")
.resizable()
.overlay(
GeometryReader { geometry in
Button(action: { }, label: {
Text("")
.frame(width: geometry.size.width, height: geometry.size.height)
.contentShape(Rectangle())
})
.buttonStyle(PlainButtonStyle())
@gabrieltheodoropoulos
gabrieltheodoropoulos / PressActionsModifier.swift
Created November 1, 2020 17:56
PressActions modifier - Handle press and release events in SwiftUI
struct PressActions: ViewModifier {
var onPress: () -> Void
var onRelease: () -> Void
func body(content: Content) -> some View {
content
.simultaneousGesture(
DragGesture(minimumDistance: 0)
.onChanged({ _ in
onPress()
@gabrieltheodoropoulos
gabrieltheodoropoulos / CustomNavigationController.swift
Last active October 11, 2020 10:42
Subclass UINavigationController to override status bar style according to top view controller's preferred style
import UIKit
class CustomNavigationController: UINavigationController {
override var preferredStatusBarStyle: UIStatusBarStyle {
return topViewController?.preferredStatusBarStyle ?? .default
}
}
@gabrieltheodoropoulos
gabrieltheodoropoulos / breakarray.swift
Last active February 14, 2020 12:10
Break an array of any type in smaller arrays
/**
Break the provided array to smaller arrays based on the specified maximum
number of items on each.
- Parameter array: The original array to break in pieces.
- Parameter maxItems: The maximum number of elements that each subarray should contain.
- Parameter datatype: The datatype of the contained data in the original
array.
- Returns: A two-dimensional array that contains the subarrays as elements.
@gabrieltheodoropoulos
gabrieltheodoropoulos / viewborders.swift
Last active October 16, 2019 11:05
iOS/Swift - A UIView extension to easily add borders on any side of any view.
/**
This is a UIView extension.
- Borders are actually UIView objects which are added as subviews to self.
- Border views are layed out to self using constraints so they'll work on any change of the view.
- Use `BorderSide` enum values to specify the sides of the view you want to add borders to.
- For each `BorderSide` value pass along the desired thickness and color of the border as associated values.
Example:
@gabrieltheodoropoulos
gabrieltheodoropoulos / stretchy_sticky_top_cell.swift
Last active January 4, 2024 08:26
iOS/Swift Tip - Add a sticky and stretchy top cell to your UITableView
// For more information, visit:
// https://gtiapps.com/?p=4482
// It is pressumed that you have added a table view (UITableView) to your view controller,
// and that you have set the view controller as the delegate of the tableview (tableView.delegate = self).
// Two different approaches are provided:
// Approach #1
// Implement the following scroll view delegate method: