Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jfuellert's full-sized avatar

Jeremy Fuellert jfuellert

  • Mayday Inc
  • Toronto, Ontario, Canada
View GitHub Profile
@jfuellert
jfuellert / DynamicAttributedTextView.swift
Last active August 8, 2022 04:26
SwiftUI HTML string parsing Text component
struct DynamicAttributedTextView: UIViewRepresentable {
// MARK: - Constants
private static let attributes: [NSAttributedString.Key : Any] = [.font: CustomFont().UIKitFont()!,
.foregroundColor: UIColor.appPrimaryText,
.paragraphStyle: DynamicAttributedTextView.paragraphStyle]
private static let types: NSTextCheckingResult.CheckingType = [.link, .address, .phoneNumber]
private static let paragraphStyle: NSParagraphStyle = {
let paragraphStyle: NSMutableParagraphStyle = NSMutableParagraphStyle()
@jfuellert
jfuellert / Example.swift
Created May 26, 2020 12:52
Easily read the size of a subview in SwiftUI
struct ExampleView: View {
// MARK: - Properties
@State private var size: CGSize = .zero
// MARK: - Updates
func body(content: Content) -> some View {
Text("Size of this label: \(Int(self.size.width)),\(Int(self.size.height))")
.modifier(SizeModifier({self.size = $0}))
}
@jfuellert
jfuellert / ScrollableView.swift
Last active April 11, 2024 17:57
A scrollable SwiftUI view, UIScrollView wrapper. ScrollableView lets you read and write content offsets for scrollview in SwiftUI, with and without animations.
import SwiftUI
struct ScrollableView<Content: View>: UIViewControllerRepresentable, Equatable {
// MARK: - Coordinator
final class Coordinator: NSObject, UIScrollViewDelegate {
// MARK: - Properties
private let scrollView: UIScrollView
var offset: Binding<CGPoint>
@jfuellert
jfuellert / gist:5bb0418871f0e30070aa
Created January 6, 2016 16:20
Returns a centered position CGRect for a given CGRect inside of a larger CGRect
/** Returns a centered position CGRect for a given CGRect inside of a larger CGRect */
CGRect centeredRect(CGRect outerRect, CGRect innerRect) {
CGRect centeredRect = innerRect;
centeredRect.origin.x = CGRectGetMidX(outerRect) - (CGRectGetWidth(innerRect) * 0.5f);
centeredRect.origin.y = CGRectGetMidY(outerRect) - (CGRectGetHeight(innerRect) * 0.5f);
return centeredRect;
}