Skip to content

Instantly share code, notes, and snippets.

View imjhk03's full-sized avatar
🪴
Gardening

Joohee Kim imjhk03

🪴
Gardening
View GitHub Profile
@imjhk03
imjhk03 / UIHelper+Zeplin.swift
Created January 9, 2021 07:26
A function to convert Zeplin line height to iOS line spacing
import UIKit
enum UIHelper {
/// Convert Zeplin line height to iOS line spacing
static func lineSpacing(from lineHeight: CGFloat, font: UIFont) -> CGFloat {
let value = lineHeight - font.lineHeight
return value
}
@imjhk03
imjhk03 / String+Extension.swift
Created December 20, 2020 13:43
String+Extension
extension String {
var isValidEmail: Bool {
let emailFormat = ""
let emailPredicate = NSPredicate(format: "SELF MATCHES %@", emailFormat)
return emailPredicate.evaluate(with: self)
}
var isValidPassword: Bool {
//Regex restricts to 8 character minimum, 1 capital letter, 1 lowercase letter, 1 number
import UIKit
extension UIView {
func addSubviews(_ views: UIView...) {
for view in views { addSubview(view) }
}
}
@imjhk03
imjhk03 / UIView+Layout.swift
Created December 13, 2020 15:57
Layout(anchor) views easily extending from UIView
import UIKit
struct AnchoredConstraints {
var top, leading, bottom, trailing, width, height: NSLayoutConstraint?
}
extension UIView {
@discardableResult
func anchor(top: NSLayoutYAxisAnchor?, leading: NSLayoutXAxisAnchor?, bottom: NSLayoutYAxisAnchor?, trailing: NSLayoutXAxisAnchor?, padding: UIEdgeInsets = .zero, size: CGSize = .zero) -> AnchoredConstraints {
@imjhk03
imjhk03 / ScreenSize and DeviceTypes of iPhone
Last active December 13, 2020 14:44
Get screen size or device types of iPhone
enum ScreenSize {
static let width = UIScreen.main.bounds.size.width
static let height = UIScreen.main.bounds.size.height
static let maxLength = max(ScreenSize.width, ScreenSize.height)
static let minLength = min(ScreenSize.width, ScreenSize.height)
}
enum DeviceTypes {
static let idiom = UIDevice.current.userInterfaceIdiom