Skip to content

Instantly share code, notes, and snippets.

@foxicode
foxicode / SnapKit.swift
Created March 19, 2020 23:37
SnapKit example
import SnapKit
class MyViewController: UIViewController {
lazy var box = UIView()
override func viewDidLoad() {
super.viewDidLoad()
self.view.addSubview(box)
@foxicode
foxicode / Makefile
Created April 6, 2020 19:44
Makefile for simple iOS app
default: app
.PHONY: clean
clean:
rm MakeTest.app/app
SDKROOT:=$(shell xcrun --sdk iphonesimulator --show-sdk-path)
app: main.m
clang -isysroot $(SDKROOT) -framework Foundation -framework UIKit -o MakeTest.app/$@ $^
@foxicode
foxicode / Info.plist
Created April 6, 2020 19:48
Info.plis of a simple iOS app
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>MakeTest</string>
<key>CFBundleExecutable</key>
<string>app</string>
@foxicode
foxicode / main.m
Created April 6, 2020 20:27
Simple iOS app source code
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(id)options {
CGRect mainScreenBounds = [[UIScreen mainScreen] bounds];
@foxicode
foxicode / Info.plist
Created April 11, 2020 22:12
Production version of Info.plist file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>MakeTest</string>
<key>CFBundleExecutable</key>
<string>app</string>
@foxicode
foxicode / CGColor+UIColor.swift
Last active April 13, 2020 18:54
Making layer attributes inspectable
import UIKit
extension CGColor {
var UIColor: UIKit.UIColor {
return UIKit.UIColor(cgColor: self)
}
}
@foxicode
foxicode / TextFieldWithPadding.swift
Created April 16, 2020 07:14
UITextField subclass with padding editable in Storyboard
import UIKit
@IBDesignable
class TextFieldWithPadding: UITextField {
@IBInspectable var paddingLeft: CGFloat = 0.0
@IBInspectable var paddingRight: CGFloat = 0.0
var padding: UIEdgeInsets {
UIEdgeInsets(top: 0, left: paddingLeft, bottom: 0, right: paddingRight)
@foxicode
foxicode / UIView+shadow.swift
Last active April 16, 2020 08:10
Swift UIKit shadows
import UIKit
extension UIView {
@IBInspectable var dropShadow: Bool {
set {
layer.shadowOffset = CGSize(width: 0, height: 0)
if newValue {
updateShadow()
} else {
@foxicode
foxicode / UITextView+padding.swift
Created April 16, 2020 08:46
UITextView subclass with padding
@IBDesignable
class TextViewWithPadding: UITextView {
@IBInspectable var paddingLeft: CGFloat = 0.0 {
didSet {
updateInsets()
}
}
@IBInspectable var paddingRight: CGFloat = 0.0 {
didSet {
@foxicode
foxicode / GradientView.swift
Created April 16, 2020 14:54
iOS gradient view
import UIKit
@IBDesignable
class GradientView: UIView {
enum Direction: Int {
case horizontal
case vertical
}
@IBInspectable var startColor: UIColor = .white {