Skip to content

Instantly share code, notes, and snippets.

@ed-yee
ed-yee / ManualSyntaxHighlight.swift
Created January 4, 2023 08:19
A hypothetical way to manually syntax highlighting a piece of code.
extension Color {
/// Create colour with integer RGB values
/// - Parameters:
/// - colorSpace: Color space
/// - red: Red colour value from 0 to 255, inclusive
/// - green: Green colour value from 0 to 255, inclusive
/// - blue: Blue colour value from 0 to 255, inclusive
/// - opacity: Opacity from 0 to 1
init(_ colorSpace: Color.RGBColorSpace = .sRGB,
@ed-yee
ed-yee / FancyAlertMessage.swift
Created July 18, 2022 14:00
Add a styled alert message
// XCode 13.4.1
// Swift 5.6.1
import UIKit
import PlaygroundSupport
class testViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.frame = CGRect(x: 0, y: 0, width: 375, height: 812)
@ed-yee
ed-yee / AlertAttributedTitle.swift
Created July 18, 2022 07:04
Set fancy title against alert "attributedTitle" property
// Define text attributes and create a fancy title
let fancyTitleAttrs: [NSAttributedString.Key: Any] = [
.font: UIFont.systemFont(ofSize: 18, weight: .bold),
.foregroundColor: UIColor.red
]
let errorTitle = NSAttributedString(string: "Error!!",
attributes: fancyTitleAttrs)
// Create an alert controller - without title.
let alert = UIAlertController(title: "Error",
@ed-yee
ed-yee / AlertMessageLeftJustify.swift
Last active July 18, 2022 07:53
Left justify UIAlertController contents (iOS Playground compatible)
// XCode 13.4.1
// Swift 5.6.1
import UIKit
import PlaygroundSupport
class testViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.frame = CGRect(x: 0, y: 0, width: 375, height: 812)
@ed-yee
ed-yee / FancyAlertWithBulletContent.swift
Last active July 20, 2022 08:21
Show an alert with fancy title and bullet list message (iOS Playground compatible)
// XCode 13.4.1
// Swift 5.6.1
import UIKit
import PlaygroundSupport
class testViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.frame = CGRect(x: 0, y: 0, width: 375, height: 812)
@ed-yee
ed-yee / FancyAlertTitleWithIcon.swift
Last active July 18, 2022 07:45
Prepend an icon to the UIAlertController title (iOS Playground compatible)
// XCode 13.4.1
// Swift 5.6.1
import UIKit
import PlaygroundSupport
class testViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.frame = CGRect(x: 0, y: 0, width: 375, height: 812)
@ed-yee
ed-yee / FancyAlertTitle.swift
Last active July 18, 2022 08:04
Demonstrate fancy alert title in iOS playground
// XCode 13.4.1
// Swift 5.6.1
class testViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.frame = CGRect(x: 0, y: 0, width: 375, height: 812)
self.view.backgroundColor = .white
}
@ed-yee
ed-yee / FancyText.swift
Last active July 15, 2022 14:30
Create fancy text with NSAttributedString (iOS Playground compatible)
import UIKit
// Define text attributes
let fancyTitleAttrs: [NSAttributedString.Key: Any] = [
.font: UIFont.systemFont(ofSize: 18, weight: .bold),
.foregroundColor: UIColor.red
]
let errorTitle = NSAttributedString(string: "Error", attributes: fancyTitleAttrs)
@ed-yee
ed-yee / SimpleUIAlertController.swift
Last active July 14, 2022 10:35
Standard single action button UIAlertController
let alert = UIAlertController(title: "Error",
message: "Invalid credential",
preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK",
style: .default,
handler: { action in
// Do something
}))