This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
timeLabel.font = FontStyles.bigTime | |
timeLabel.adjustsFontForContentSizeCategory = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let label = UILabel() | |
label.font = UIFont.preferredFont(forTextStyle: .caption1) | |
label.adjustsFontForContentSizeCategory = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stackView.axis = traitCollection.preferredContentSizeCategory > .extraExtraExtraLarge ? .vertical : .horizontal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { | |
stack.axis = traitCollection.preferredContentSizeCategory > .extraExtraExtraLarge ? .vertical : .horizontal | |
} |
OlderNewer