info

category : App Develop
[Swift]UITableView deleteRows  @ App Develop , Swift 2017年4月1日
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
}
[Swift]UITableView insertRows  @ App Develop , Swift 2017年3月1日
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
}
[Swift]Array Extension #2  @ App Develop , Swift 2017年1月2日
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
}
[Swift]getUIColorByColorTuple  @ App Develop , Swift 2016年9月1日
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)
}
[Swift]UISwitchButton  @ App Develop , Swift 2016年8月4日
UISwitchButton
class UISwitchButton: UIButton {
    let onImage = UIImage(named: "check-on")
    let offImage = UIImage(named: "check-off")
    
    var isTapped: Bool = false {
        didSet {
            if isTapped {
                self.setImage(onImage, forState: .Normal)
            } else {
                self.setImage(offImage, forState: .Normal)
            }
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.isTapped = false
        self.setImage(offImage, forState: .Normal)
        self.addTarget(self, action: #selector(UISwitchButton.tapButton(_:)), forControlEvents: UIControlEvents.TouchUpInside)
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    override func awakeFromNib() {
        self.addTarget(self,action:#selector(UISwitchButton.tapButton(_:)), forControlEvents: UIControlEvents.TouchUpInside)
        self.isTapped = false
    }
    func tapButton(sender: UIButton) {
        if sender == self {
            isTapped = !isTapped
        }
    }
}
[Swift]UIAlertController  @ App Develop , Swift 2016年8月1日
UIAlertController
let alertController:UIAlertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction( UIAlertAction(title: cancelTitle, style: UIAlertActionStyle.Cancel, handler: { (action:UIAlertAction) in

} )
)
alertController.addAction( UIAlertAction(title: okTitle, style: UIAlertActionStyle.Default, handler: { (action:UIAlertAction) in

} )
)
self.presentViewController(alertController, animated: true, completion: { 
    
})