Skip to content

Instantly share code, notes, and snippets.

Avatar

DAO daoseng33

View GitHub Profile
View RemoveTextViewPadding.swift
// 移除上下的間距
textView.textContainerInset = .zero
// 移除左右的間距
textView.textContainer.lineFragmentPadding = 0
@daoseng33
daoseng33 / 佛祖.swift
Created Jan 13, 2019
佛祖保佑 永無BUG
View 佛祖.swift
//
// _ooOoo_
// o8888888o
// 88" . "88
// (| -_- |)
// O\ = /O
// ____/`---'\____
// . ' \\| |// `.
// / \\||| : |||// \
// / _||||| -:- |||||- \
View isBeingPresented.swift
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if isBeingPresented {
// start timer
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
View isMovingToParent.swift
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if isMovingToParent {
// start timer
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
View EnumCount3.swift
enum SectionTypes: CaseIterable {
case header
case list
}
print(SectionTypes.allCases.count) // 2
View EnumCount2.swift
enum SectionType: Int {
case header = 0
case list
static let count = 2
}
print(SectionType.count) // 2
View EnumCount1.swift
enum SectionType: Int {
case header = 0
case list
static let count: Int = {
var max: Int = 0
while let _ = SectionType(rawValue: max) { max += 1 }
return max
}()
}
@daoseng33
daoseng33 / generateQRCode.swift
Last active Nov 8, 2018
Generate high resolution QR Code in swift
View generateQRCode.swift
static func generateQRCode(from string: String, imageView: UIImageView) -> UIImage? {
let data = string.data(using: String.Encoding.ascii)
if let filter = CIFilter(name: "CIQRCodeGenerator") {
filter.setValue(data, forKey: "inputMessage")
// L: 7%, M: 15%, Q: 25%, H: 30%
filter.setValue("M", forKey: "inputCorrectionLevel")
if let qrImage = filter.outputImage {
let scaleX = imageView.frame.size.width / qrImage.extent.size.width
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 PopGestureRecognizer.swift
self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false