[Swift]UIView Extension #7
UIView Extension #7
var isVisible:Bool{ get{ return !self.isHidden } set{ self.isHidden = !newValue } }
UIView Extension #7
var isVisible:Bool{ get{ return !self.isHidden } set{ self.isHidden = !newValue } }
addObserverでresize event
self.contentView.addObserver(self, forKeyPath: "frame", options: NSKeyValueObservingOptions(rawValue: 0), context: nil)
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { //処理 }
addGestureRecognizer
let gest = UILongPressGestureRecognizer(target: self, action: #selector(self.onPushTargetView)) self.targetView.addGestureRecognizer(gest)
プログラムによるflexibleWidth,flexibleHeight
self.targetView.frame = self.parentView.bounds self.targetView.autoresizingMask = [ .flexibleWidth, .flexibleHeight ]
deleteRows
self.mainTableView.beginUpdates() self.data.remove(at: 0) self.mainTableView.deleteRows(at: [IndexPath(row:0, section: 0)], with: UITableViewRowAnimation.top) self.mainTableView.endUpdates()
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return self.data.count }
insertRows
self.mainTableView.beginUpdates() self.data.insert("jack", at: 0) self.mainTableView.insertRows(at: [IndexPath(row:0, section:0)], with:UITableViewRowAnimation.top) self.mainTableView.endUpdates()
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return self.data.count }
DispatchQueue #1
//0.02秒後に実行 DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.02) { //処理 }
String extension #1
extension String { mutating func trim() -> String{ return self.trimmingCharacters(in: .whitespacesAndNewlines) } }
Array Extension #2
mutating func switchValue(_ index1:Int,index2:Int){ let _index1:Int = (index1 < 0) ? self.count + index1 : index1 let _index2:Int = (index2 < 0) ? self.count + index2 : index2 let elm = self[_index1] self[_index1] = self[_index2] self[_index2] = elm }
typealias rgbTuple = (r:CGFloat,g:CGFloat,b:CGFloat)
func getUIColorByColorTuple(color:rgbTuple, alpha:CGFloat=1.0, luminanceScale:CGFloat = 1.0) -> UIColor{ var colort:rgbTuple = (r:color.r,g:color.g,b:color.b) let rl:CGFloat = 0.298912 * colort.r colort.r = rl * luminanceScale / 0.298912 let gl:CGFloat = 0.586611 * colort.g colort.g = gl * luminanceScale / 0.586611 let bl:CGFloat = 0.114478 * colort.b colort.b = bl * luminanceScale / 0.114478 return UIColor(red: colort.r, green: colort.g, blue: colort.b, alpha: alpha) }