Skip to content

Instantly share code, notes, and snippets.

@daoseng33
daoseng33 / 佛祖.swift
Created Jan 13, 2019
佛祖保佑 永無BUG
View 佛祖.swift
//
// _ooOoo_
// o8888888o
// 88" . "88
// (| -_- |)
// O\ = /O
// ____/`---'\____
// . ' \\| |// `.
// / \\||| : |||// \
// / _||||| -:- |||||- \
View LeftAlignedCollectionViewFlowLayout.swift
class LeftAlignedCollectionViewFlowLayout: UICollectionViewFlowLayout {
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
let attributes = super.layoutAttributesForElements(in: rect)
var leftMargin = sectionInset.left
var maxY: CGFloat = -1.0
attributes?.forEach { layoutAttribute in
if layoutAttribute.frame.origin.y >= maxY {
leftMargin = sectionInset.left
View isMovingToParent.swift
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if isMovingToParent {
// start timer
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
View layerMask.swift
let maskPath = UIBezierPath(roundedRect: view.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 5, height: 5))
let maskLayer = CAShapeLayer()
maskLayer.frame = view.bounds
maskLayer.path = maskPath.cgPath
view.layer.mask = maskLayer
View BadgeBar.swift
import UIKit
public class BadgeBarButtonItem: UIBarButtonItem {
@IBInspectable
public var badgeNumber: Int = 0 {
didSet {
self.updateBadge()
}
}
View ~=.swift
print(0..<200 ~= 159) // true
print(0..<200 ~= 201) // false
View resetUserDefault.swift
let domain = Bundle.main.bundleIdentifier!
UserDefaults.standard.removePersistentDomain(forName: domain)
View toggle.swift
var isLike = false
if isLike {
fetchDisLikeAPI()
} else {
fetchLikeAPI()
}
isLike.toggle()
View isLikeExample.swift
var isLike = false
if isLike {
fetchDisLikeAPI()
} else {
fetchLikeAPI()
}
isLike = !isLike