This sheet goes along with this SSH YouTube tutorial
$ ssh [email protected]
$ mkdir test
$ cd test
// Author: SwiftUI-Lab (swiftui-lab.com) | |
// Description: this learning tool is designed to showcase the different | |
// Grid and GridRow view options, added in SwiftUI 2022. It is part of the | |
// blog article: https://swiftui-lab.com/eager-grids | |
// | |
import SwiftUI | |
import UniformTypeIdentifiers | |
// The root view of the application | |
struct ContentView: View { |
// Taken from Apple's App Dev Training: https://developer.apple.com/tutorials/app-dev-training/ | |
/// This color is either black or white, whichever is more accessible when viewed against the scrum color. | |
var accessibleFontColor: Color { | |
var red: CGFloat = 0 | |
var green: CGFloat = 0 | |
var blue: CGFloat = 0 | |
UIColor(self).getRed(&red, green: &green, blue: &blue, alpha: nil) | |
return isLightColor(red: red, green: green, blue: blue) ? .black : .white | |
} |
// Douglas Hill, November 2019 | |
// Find the latest version of this file at https://github.com/douglashill/KeyboardKit | |
import UIKit | |
/// A scroll view that allows scrolling using a hardware keyboard like `NSScrollView`. | |
/// Supports arrow keys, option + arrow keys, command + arrow keys, space bar, page up, page down, home and end. | |
/// Limitations: | |
/// - Paging scroll views (isPagingEnabled = true) are not supported yet. | |
/// - The scroll view must become its own delegate so setting the delegate is not supported yet. |
$ ssh [email protected]
$ mkdir test
$ cd test
class MyView : UIView { | |
func buildMyView() { | |
var indicatorView :UIActivityIndicatorView! | |
let indicatorSize : CGFloat = 120 | |
loadingIndicator = UIView(frame: CGRect(origin: CGPoint.zero, size: CGSize(width: indicatorSize, height: indicatorSize))) | |
loadingIndicator.backgroundColor = UIColor.darkGray.withAlphaComponent(0.7) | |
loadingIndicator.layer.cornerRadius = 10.0 | |
indicatorView = UIActivityIndicatorView(activityIndicatorStyle: .white) | |
indicatorView.hidesWhenStopped = false |
class GradientLineView: UIView { | |
override func draw(_ rect: CGRect) { | |
if let context = UIGraphicsGetCurrentContext() { | |
let startPoint1 = CGPoint(x: 20, y: rect.height/2) | |
let endPoint1 = CGPoint(x: rect.width-120, y: rect.height/2) | |
context.setLineWidth(15) | |
context.move(to: startPoint1) | |
context.addLine(to: endPoint1) | |
context.setLineCap(.round) |
extension UIImage { | |
public func imageRotatedByDegrees(degrees: CGFloat) -> UIImage { | |
let radiansToDegrees: (CGFloat) -> CGFloat = { | |
return $0 * (180.0 / CGFloat(M_PI)) | |
} | |
let degreesToRadians: (CGFloat) -> CGFloat = { | |
return $0 / (180.0 * CGFloat(M_PI)) | |
} | |
// calculate the size of the rotated view's containing box for our drawing space |
if { | |
something(); | |
// } else { | |
// somethingElse(); | |
} |
extension Int { | |
func bottlesOfBeer() { | |
let bottles = "\(self) bottle" + (self == 1 ? "" : "s") | |
let what = " of beer on the wall" | |
println("\(bottles + what), \(bottles) of beer.") | |
print("Take one down, pass it around, ") | |
if self == 1 { | |
println("no more bottles\(what).") |
//A review thanks to http://bost.ocks.org/mike/algorithms/ | |
import Foundation | |
func exchange<T>(inout elementsIn array: [T], i: Int, j: Int) | |
{ | |
let temp: T = array[i] | |
array[i] = array[j] | |
array[j] = temp | |
} |