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
// 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
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
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
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
inputTextField.addTarget(self, action: #selector(textFieldDidChange(_:)) , for: UIControlEvents.editingChanged) | |
@objc func textFieldDidChange(_ textField: UITextField) { | |
// text field did change | |
} |
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
// Draw dotted line | |
let viewBorder = CAShapeLayer() | |
viewBorder.lineDashPattern = [2, 2] | |
viewBorder.frame = myView.bounds | |
viewBorder.fillColor = nil | |
viewBorder.path = UIBezierPath(rect: myView.bounds).cgPath | |
myView.layer.addSublayer(viewBorder) |
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
@IBAction func textFieldDidChange(_ sender: UITextField) { | |
if let text = sender.text { | |
let uppercase = text.uppercased() | |
sender.text = uppercase | |
} | |
} |
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 up the shape of the circle | |
CAShapeLayer *border = [CAShapeLayer layer]; | |
border.path = [UIBezierPath bezierPathWithRoundedRect:self.myImageView.frame cornerRadius:self.myImageView.frame.size.height/2].CGPath; | |
border.anchorPoint = CGPointMake(0.5, 0.5); | |
border.position= CGPointMake(self.myImageView.bounds.origin.x, self.myImageView.bounds.origin.y); | |
border.fillColor = [UIColor clearColor].CGColor; | |
border.strokeColor = [UIColor blueColor].CGColor; | |
border.lineWidth = 5; [self.view.layer addSublayer:border]; | |
// Configure animation | |
// draw Border |