Skip to content

Instantly share code, notes, and snippets.

View cwalo's full-sized avatar

Corey Walo cwalo

View GitHub Profile
@cwalo
cwalo / IndentScrollView
Last active July 9, 2024 21:36
IndentScrollView - A paging ScrollView that tracks the target content view
import SwiftUI
struct IndentScrollView: View {
let min = 0.5
let max = 3.5
let increment = 0.1
@State
var multiplier = 0.5
//
// BottomSheetView.swift
// field
//
// Created by Corey Walo on 12/21/22.
//
import SwiftUI
fileprivate enum Constants {
protocol FooProtocol {}
protocol BarProtocol {}
protocol DootProtocol {}
typealias CompProtocol = FooProtocol & BarProtocol & DootProtocol
struct Dependencies: CompProtocol {}
struct SomeType {
@cwalo
cwalo / HeightOfStringFittingWidth.swift
Created June 7, 2019 03:31
How to calculate the height of a string fitting a given width
func heightOfString(_ string: String, attributes: [NSAttributedString.Key: Any], fitting width: CGFloat) -> CGFloat {
let constraintRect = CGSize(width: width, height: CGFloat.greatestFiniteMagnitude)
let boundingRect = string.boundingRect(with: constraintRect,
options: [.usesLineFragmentOrigin, .usesFontLeading],
attributes: attributes,
context: nil)
return boundingRect.size.height
}
@cwalo
cwalo / things_you_should_know.md
Last active June 29, 2020 14:59
Things you should know, but might forget...

Things you should know, but might forget...

This is a curated list of reference material that anyone who develops in the Apple domain will hopefully find helpful. Most items are things I have used and can vouch for.

--

Swift

--

The Swift Programming Language

Swift Forums

@cwalo
cwalo / AddShadowAndRoundedCorners.swift
Created January 10, 2018 19:44
Override layoutSubviews to add a new layer using a path with a roundedRect and cornerRadius
private var shadowLayer: CAShapeLayer!
private var cornerRadius: CGFloat = 25.0
private var fillColor: UIColor = .blue // the color applied to the shadowLayer, rather than the view's backgroundColor
override func layoutSubviews() {
super.layoutSubviews()
if shadowLayer == nil {
shadowLayer = CAShapeLayer()
@cwalo
cwalo / RoundShadowView.swift
Created December 29, 2017 00:10
UIView with cornerRadius and Shadow
/*
Example of how to create a view that has rounded corners and a shadow.
These cannot be on the same layer because setting the corner radius requires masksToBounds = true.
When it's true, the shadow is clipped.
It's possible to add sublayers and set their path with a UIBezierPath(roundedRect...), but this becomes difficult when using AutoLayout.
Instead, we a containerView for the cornerRadius and the current view for the shadow.
All subviews should just be added and constrained to the containerView
*/
import UIKit
@cwalo
cwalo / String+Emoji.swift
Created October 4, 2017 00:49
String+Emoji
import Foundation
extension String {
var containsEmoji: Bool {
for scalar in unicodeScalars {
switch scalar.value {
case 0x1F600...0x1F64F, // Emoticons
0x1F300...0x1F5FF, // Misc Symbols and Pictographs
0x1F680...0x1F6FF, // Transport and Map
0x1F900...0x1F9FF, //idk but here lies clown and others