Skip to content

Instantly share code, notes, and snippets.

@krummler
krummler / String+CheckEmoji.swift
Last active July 7, 2022 10:39
Emoji checking, with some legacy code
import Foundation
extension UnicodeScalar {
/// Note: This method is part of Swift 5, so you can omit this.
/// See: https://developer.apple.com/documentation/swift/unicode/scalar
var isEmoji: Bool {
switch value {
case 0x1F600...0x1F64F, // Emoticons
0x1F300...0x1F5FF, // Misc Symbols and Pictographs
0x1F680...0x1F6FF, // Transport and Map
@krummler
krummler / String+EmojiCheck.swift
Last active December 26, 2023 10:21
Emoji Checking for Swift 5.0 and up
import Foundation
extension Character {
/// A simple emoji is one scalar and presented to the user as an Emoji
var isSimpleEmoji: Bool {
return unicodeScalars.count == 1 && unicodeScalars.first?.properties.isEmojiPresentation ?? false
}
/// Checks if the scalars will be merged into and emoji
var isCombinedIntoEmoji: Bool {
//: A UIKit based Playground for presenting user interface
import PlaygroundSupport
import UIKit
class MyViewController: UIViewController {
let button1 = UIButton()
let button2 = UIButton()
let button3 = UIButton()
let button4 = UIButton()
@krummler
krummler / article-button-styling-code1.swift
Last active April 9, 2020 10:12
Article - Simple button styling
button.backgroundColor = UIColor(named: "buttonBackground")
button.layer.cornerRadius = 8
button.layer.shadowColor = UIColor(named: "buttonShadow")?.cgColor
button.layer.shadowOpacity = 0.8
button.layer.shadowOffset = CGSize(width: 1, height: 1)
button.layer.borderWidth = 2
button.layer.borderColor = UIColor(named: "buttonBorder")?.cgColor
extension UIFont {
func with(style: UIFont.TextStyle, basePointSize: CGFloat, maxPointSize: CGFloat? = nil) -> UIFont {
if let maxPointSize = maxPointSize {
return UIFontMetrics(forTextStyle: style).scaledFont(for: self.withSize(basePointSize),
maximumPointSize: maxPointSize)
}
return UIFontMetrics(forTextStyle: style).scaledFont(for: self.withSize(basePointSize))
}
}
struct FontStyles {
private static let customFont = UIFont(name: "Cochin", size: 15)!
static let headline = customFont.with(style: .headline, basePointSize: 34)
static let body = customFont.with(style: .body, basePointSize: UIFont.labelFontSize)
static let bigTime = customFont.withSize(66)
static let buttonPrimary = customFont.with(style: .body, basePointSize: UIFont.buttonFontSize)
static let buttonSecondary = customFont.with(style: .caption1, basePointSize: UIFont.smallSystemFontSize)
}
timeLabel.font = FontStyles.bigTime
timeLabel.adjustsFontForContentSizeCategory = false
let label = UILabel()
label.font = UIFont.preferredFont(forTextStyle: .caption1)
label.adjustsFontForContentSizeCategory = true
stackView.axis = traitCollection.preferredContentSizeCategory > .extraExtraExtraLarge ? .vertical : .horizontal
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
stack.axis = traitCollection.preferredContentSizeCategory > .extraExtraExtraLarge ? .vertical : .horizontal
}