Skip to content

Instantly share code, notes, and snippets.

extension UITextView {
func removeTextPadding() {
textContainer.lineFragmentPadding = 0
textContainerInset = .zero
}
}
// 移除上下的間距
textView.textContainerInset = .zero
// 移除左右的間距
textView.textContainer.lineFragmentPadding = 0
@daoseng33
daoseng33 / 佛祖.swift
Created January 13, 2019 05:59
佛祖保佑 永無BUG
//
// _ooOoo_
// o8888888o
// 88" . "88
// (| -_- |)
// O\ = /O
// ____/`---'\____
// . ' \\| |// `.
// / \\||| : |||// \
// / _||||| -:- |||||- \
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if isBeingPresented {
// start timer
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if isMovingToParent {
// start timer
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
enum SectionTypes: CaseIterable {
case header
case list
}
print(SectionTypes.allCases.count) // 2
enum SectionType: Int {
case header = 0
case list
static let count = 2
}
print(SectionType.count) // 2
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 November 8, 2018 07:09
Generate high resolution QR Code in 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
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