This file contains 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
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 |
This file contains 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
DispatchQueue.global(qos: .background).async { // 背景線程 | |
let initialIndex = self.datas.count // 原本已有的 20 筆資料 | |
var indexPaths: [IndexPath] = [] // 將要加入新項目的懵懂 array | |
for index in 0..<newPackOfDatas.count { // 將 indexPaths 加入新的 20 筆資料 | |
let indexPath = IndexPath(item: initialIndex + index, section: 0) // 注意起始位置是 20(initialIndex 為還沒更新前的資料 count) | |
indexPaths.append(indexPath) | |
} | |
self.datas += newPackOfDatas // 將新的資料加入 datas |
This file contains 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
UIView.setAnimationsEnabled(false) // 我夾 | |
self.tableView.insertRows(at: indexPaths, with: .none) | |
UIView.setAnimationsEnabled(true) // 我夾 |
This file contains 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
// Set textfield max length | |
private var __maxLengths = [UITextField: Int]() | |
extension UITextField { | |
@IBInspectable var maxLength: Int { | |
get { | |
guard let l = __maxLengths[self] else { | |
return Int.max // (global default-limit. or just, Int.max) | |
} | |
return l | |
} |
This file contains 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
self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false |
This file contains 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 |
This file contains 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 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 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 |