Skip to content

Instantly share code, notes, and snippets.

Avatar

Samuel Défago defagos

View GitHub Profile
@defagos
defagos / UITextView+SDECursorVisibility.m
Last active August 29, 2015 14:08
A category for iOS 7 ensuring that UITextView cursor stays within the content area defined by its contentInset. This behavior is standard in iOS 8
View UITextView+SDECursorVisibility.m
//
// UITextView+SDECursorVisibility.m
//
// Created by Samuel Défago on 29.10.14.
//
#import <UIKit/UIKit.h>
@interface UITextView (SDECursorVisibility)
@defagos
defagos / gist:267d3b8b30604fac541f
Created December 2, 2014 10:59
git commit hook ensuring the correct branch URL is set for Travis badges found in README files. Install both as post-commit and post-merge hooks
View gist:267d3b8b30604fac541f
#!/bin/sh
# Repository settings
REPOSITORY_NAME="YourRepositoryName"
README_FILE_NAME="README.markdown"
# Update a Travis badge URL found in the README to keep it in sync with the branch name
# Badge example:
# [![Build Status](https://img.shields.io/travis/$USER_NAME/$REPOSITORY_NAME/master.svg?style=flat)](https://travis-ci.org/$USER_NAME/$REPOSITORY_NAME)
branch_name=`git symbolic-ref --short HEAD`
@defagos
defagos / uncrustify-objc.cfg
Last active September 7, 2016 11:35
My Objective-C Uncrustify configuration file
View uncrustify-objc.cfg
#
# Uncrustify Configuration File
# File Created With UncrustifyX 0.4.3 (252)
#
# Alignment
# ---------
## Alignment
View example_block_swizzling.m
@implementation UILabel (SwizzlingExamples)
+ (void)load
{
SwizzleSelectorWithBlock_Begin(self, @selector(initWithFrame:))
^(UILabel *self, CGRect frame) {
if ((self = ((id (*)(id, SEL, CGRect))_imp)(self, _cmd, frame))) {
// ...
}
return self;
@defagos
defagos / BodyCounter.swift
Last active December 13, 2022 16:07
Decorate the view with a bordered debugging frame whose attached label displays how many times the view body has been evaluated.
View BodyCounter.swift
import SwiftUI
import UIKit
private struct BodyCounterView: UIViewRepresentable {
let color: UIColor
private let id = UUID() // Force view updates
func makeUIView(context: Context) -> _BodyCounterView {
let view = _BodyCounterView()
@defagos
defagos / ExampleView.swift
Created September 28, 2021 21:04
Send a message to the UIKit responder chain from a SwiftUI view
View ExampleView.swift
@objc protocol ExampleActions: AnyObject {
func pushUIKitViewController()
}
struct ExampleView: View {
@FirstResponder private var firstResponder
var body: some View {
Button {
firstResponder.sendAction(#selector(ExampleActions.pushUIKitViewController))