Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View macguru's full-sized avatar

Max Seelemann macguru

View GitHub Profile
@macguru
macguru / ContentView.swift
Created March 8, 2024 08:09
SwiftUI view to try out SF Pro with various widths and weights
import SwiftUI
struct ContentView: View {
@State var width: Float = 0
@State var weight: Float = 0
var body: some View {
VStack {
HStack{
Text("Width")
@macguru
macguru / SwiftUIView.swift
Last active November 9, 2022 17:00
Adapter view to use a (wrapping) SwiftUI view with auto layout, where a certain width is pre-defined
import SwiftUI
public final class SwiftUIView<Content: View>: UIView {
private let hostingController: UIHostingController<Content>
public init(rootView: Content) {
hostingController = UIHostingController(rootView: rootView)
super.init(frame: .zero)
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSLog(@"languages: %@", [NSLocale.preferredLanguages componentsJoinedByString: @", "]);
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString: @"暗a"];
@macguru
macguru / UIViewController+Rotation.m
Created April 11, 2018 15:30
Forcing a rotation on a UIViewController.
//
// UIViewController+Rotation.m
// Ulysses
//
// Created by Götz Fabian on 12.10.17.
// Copyright © 2017 Ulysses GmbH & Co. KG. All rights reserved.
//
#import "UIViewController+Rotation.h"
@macguru
macguru / SwizzlingTextView.m
Last active January 6, 2018 15:55
Swizzling behaviour into TISmartPunctuationController
@implementation SwizzlingTextView /* Subclass of UITextView */
{
BOOL _swizzled;
}
/* working solution */
- (void)setInputDelegate:(id<UITextInputDelegate>)inputDelegate
{
[super setInputDelegate: inputDelegate];
@macguru
macguru / MXSEventTrackingWindow.h
Created September 2, 2016 10:47
Tell if a user interaction is currently happening though a touch event in a view's window or something else – like an external keyboard or interaction in a different window (keyboard window). Example use: check if selection change was through touch or external keyboard.
//
// MXSEventTrackingWindow.h
//
// Created by Max Seelemann on 01.09.16.
// Copyright © 2016 The Soulmen. All rights reserved.
//
/*!
@abstract Special window class used for advanced event processing.
*/
@macguru
macguru / gist:b7a01e3f0e9ae6f350d5
Last active May 10, 2020 20:58
Interface sizes a regular Universal app must support with iOS 11 when supporting all devices. Starts with iPhone 5 and goes up to iPad Pro 12.9".
COMPACT WIDTH (stacked view)
- 320 x 568 pt
-> iPhone 5, 5s
- 320 x 768 pt
-> iPad 9.7" Split Landscape 2/3 right
- 320 x 834 pt
-> iPad 10.5" Split Landscape 2/3 right
- 320 x 1024 pt
-> iPad 9.7" Split Portrait right
@macguru
macguru / gist:17ee7d47acbb4d4a2258
Created May 28, 2014 13:33
Enforce device rotation by using a temporary window and view controller.
@interface FixedViewController : UIViewController
@property(nonatomic) NSUInteger supportedInterfaceOrientations;
@end
@implementation FixedViewController
@end
...
- (void)rotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
+ (NSCharacterSet *)ignoredCharactersBeforeSmartInserts
{
static NSCharacterSet *characterSet;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
/*
Character set taken from AppKit's __getPreSmartSet
*/
NSMutableCharacterSet *mutableSet = [NSMutableCharacterSet characterSetWithCharactersInString:@"([\\\"'#$/-`{<"];