Skip to content

Instantly share code, notes, and snippets.

View Mx-Iris's full-sized avatar

Mx-Iris

View GitHub Profile
@mcgtts
mcgtts / VerticallyAlignedLabel.m
Created March 26, 2013 12:11
UILabel 里放入多行文字,会发现 label 默认居中对齐,很不符合左对齐的传统习惯,下面这段 CocoaChina 版主“angellixf”分享的代码可以让 UILabel 以垂直方向顶端对齐,也就是我们常说的左对齐或右对齐
//
// VerticallyAlignedLabel.h
//
#import <Foundation/Foundation.h>
typedef enum VerticalAlignment {
VerticalAlignmentTop,
VerticalAlignmentMiddle,
@eiskalteschatten
eiskalteschatten / ImageResizer.swift
Last active January 24, 2024 15:58
A function written in Swift to resize an NSImage proportionately
//
// ImageResizer.swift
//
// Created by Alex Seifert on 18/06/2016.
// http://www.alexseifert.com
//
import Foundation
import Cocoa
@fzwo
fzwo / LegacyDocsets.md
Last active May 15, 2024 10:16
Download and view old Apple developer documentation

How to download and view legacy documentation from Apple (no need to sign in to your dev account)

  1. Download the docset index XML.
  2. Find the docset you want (there are some with URL https://apple.com/none.dmg; ignore them - you will find them again further down the file with a working URL).
  3. Download the dmg. It's probably around a gigabyte or so.
  4. "Install" the .pkg file somewhere on your disk. If you don't trust the installer, do it manually:
    1. Find the largest file, named Payload, and extract it using The Unarchiver.
    2. This creates a new, even larger file, probably named Payload-1.
    3. Extract Payload-1 using The Unarchiver.
  5. After many minutes of extracting, we have our .docset file.
@CrystDragon
CrystDragon / MyTextLabel.swift
Created May 17, 2018 08:19
Most basic custom UITextInput conformance, without selection interaction, no UI elements but only pure texts.
import UIKit
class MyTextLabel: UIView {
var textLayer = CATextLayer()
var textStorage: String = "" {
didSet {
textLayer.string = textStorage
}
}
@stefanceriu
stefanceriu / UICollectionView+CTX.h
Last active June 21, 2024 05:12
Enabled iOS style UICollectionView multiple selection on Catalyst applications
//
// UICollectionView+CTX.h
// EFClass-Mac
//
// Created by Stefan Ceriu on 29/11/2019.
// Copyright © 2019 EF Education First. All rights reserved.
//
#import <Foundation/Foundation.h>
@IsaacXen
IsaacXen / README.md
Last active July 17, 2024 08:21
(Almost) Every WWDC videos download links for aria2c.
@douglashill
douglashill / FourColumns.swift
Created June 23, 2020 21:05
A sample UIKit app that sets up a four column layout with new iOS 14 API on UISplitViewController.
import UIKit
class FourColumnsContainerViewController: UIViewController {
let outerSplitViewController = UISplitViewController(style: .tripleColumn)
let innerSplitViewController = UISplitViewController(style: .doubleColumn)
let primary = makeContentViewController("App")
let secondary = makeContentViewController("Files")
let mainContent = makeContentViewController("File Content")
let inspector = makeContentViewController("Inspector")
@rjchatfield
rjchatfield / ArrayBuilder.swift
Last active September 7, 2023 07:20
ArrayBuilder - Swift ~~FunctionBuilder~~ ResultBuilder
@resultBuilder
public struct ArrayBuilder<Element> {
public static func buildPartialBlock(first: Element) -> [Element] { [first] }
public static func buildPartialBlock(first: [Element]) -> [Element] { first }
public static func buildPartialBlock(accumulated: [Element], next: Element) -> [Element] { accumulated + [next] }
public static func buildPartialBlock(accumulated: [Element], next: [Element]) -> [Element] { accumulated + next }
// Empty Case
public static func buildBlock() -> [Element] { [] }
// If/Else
struct KeychainItem {
// MARK: Nested Types
enum KeychainError: Error {
case noPassword
case unexpectedPasswordData
case unexpectedItemData
case unhandledError(status: OSStatus)
}
@frankschlegel
frankschlegel / Combine+SelfBindings.swift
Last active February 17, 2024 02:14
Convenience extensions for Combine adding memory-save bindings and Cancellable management
import Combine
/// Classes implementing this protocol can be target of convenience Publisher
/// bindings and assignments without causing accidental retain cycles.
/// Those bindings and assignments are also released together with the target.
///
/// For example:
///
/// aPublisher.bind(to: self) { me, object in