This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UITextView { | |
func removeTextPadding() { | |
textContainer.lineFragmentPadding = 0 | |
textContainerInset = .zero | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 移除上下的間距 | |
textView.textContainerInset = .zero | |
// 移除左右的間距 | |
textView.textContainer.lineFragmentPadding = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// _ooOoo_ | |
// o8888888o | |
// 88" . "88 | |
// (| -_- |) | |
// O\ = /O | |
// ____/`---'\____ | |
// . ' \\| |// `. | |
// / \\||| : |||// \ | |
// / _||||| -:- |||||- \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(animated) | |
if isBeingPresented { | |
// start timer | |
} | |
} | |
override func viewWillDisappear(_ animated: Bool) { | |
super.viewWillDisappear(animated) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(animated) | |
if isMovingToParent { | |
// start timer | |
} | |
} | |
override func viewWillDisappear(_ animated: Bool) { | |
super.viewWillDisappear(animated) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum SectionTypes: CaseIterable { | |
case header | |
case list | |
} | |
print(SectionTypes.allCases.count) // 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum SectionType: Int { | |
case header = 0 | |
case list | |
static let count = 2 | |
} | |
print(SectionType.count) // 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |