info

Home
[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
        }
    }
}
[JavaScript]get OS version  @ JavaScript 2016年8月2日
get OS version
function getiOSVersion(){
	if (/iP(hone|od|ad)/.test(navigator.userAgent)) {
		var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
		return parseInt(parseInt(v[1], 10).toString()+parseInt(v[2], 10).toString()+parseInt(v[3] || 0, 10).toString() ,10);
	}
	return 0.0;
}
function getAndroidVersion(){
	if( navigator.userAgent.indexOf("Android") > 0 ) {
		var v = navigator.userAgent.match(/Android [\d\.]+/)[0].split(' ').pop().split('.');
		return parseInt(parseInt(v[0], 10).toString()+parseInt(v[1], 10).toString()+parseInt(v[2] || 0, 10).toString() ,10);
	}
	return 0.0;
}
[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: { 
    
})
[Swift]自作UIRefreshControl  @ App Develop , Swift 2016年7月1日
自作UIRefreshControl
let REFRESH_HEIGHT:CGFloat = 66.0
var readyRefresh:Bool = false
var defaultInsetTop:CGFloat = 0.0

func scrollViewDidScroll(scrollView: UIScrollView) {
    if self.readyRefresh {
        if -self.REFRESH_HEIGHT < scrollView.contentInset.top + scrollView.contentOffset.y {
            self.readyRefresh = false
        }
    }else {
        if -self.REFRESH_HEIGHT >= scrollView.contentInset.top + scrollView.contentOffset.y {
            self.readyRefresh = true
        }
    }
}
func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) {
    if !self.readyRefresh {
        return
    }
    self.readyRefresh = false
    self.defaultInsetTop = self.tableView.contentInsetTop
    UIView.setAnimationBeginsFromCurrentState(true)
    UIView.animateWithDuration(NSTimeInterval(0.3), delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.0, options: UIViewAnimationOptions.CurveLinear,
        animations: { () -> Void in
            self.tableView.contentInsetTop = self.REFRESH_HEIGHT
        },
        completion: { (finish:Bool) -> Void in
        }
    )
    
    self.executeRefresh()
}
private func endRefresh(){
    UIView.setAnimationBeginsFromCurrentState(true)
    UIView.animateWithDuration(NSTimeInterval(0.3), delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.0, options: UIViewAnimationOptions.CurveLinear,
        animations: { () -> Void in
            self.tableView.contentInsetTop = self.defaultInsetTop
        },
        completion: { (finish:Bool) -> Void in
        }
    )
}
private func executeRefresh(){
    //処理
    
    self.endRefresh()
}
[Swift]文字列分割  @ App Develop , Swift 2016年6月7日
文字列分割
let datetimeString:String = "2016-02-17 14:51:21"
let tmp:[String] = datetimeString.componentsSeparatedByCharactersInSet(NSCharacterSet(charactersInString:"- :"))
print(tmp)

出力結果
["2016", "02", "17", "14", "51", "21"]
[Swift]UIView Extension #6  @ App Develop , Swift 2016年6月5日
UIView Extension #6
func animateBG2Black(duration:CGFloat=0.3){
    UIView.setAnimationBeginsFromCurrentState(true)
    UIView.animateWithDuration(NSTimeInterval(duration), delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.0, options: UIViewAnimationOptions.CurveLinear,
        animations: { () -> Void in
            self.backgroundColor = UIColor.blackColor()
        },
        completion: { (finish:Bool) -> Void in
            
        }
    )
}
[Swift]Array Extension #1  @ App Develop , Swift 2016年6月4日
Array Extension #1
extension Array {
    mutating func firstToLast(){
        let elm = self.removeFirst()
        self.append(elm)
    }
    mutating func lastToFirst(){
        let elm = self.removeLast()
        self.insert(elm, atIndex: 0)
    }
}

使用
var tmp1:[Int] = [0,1,2,3]
tmp1.firstToLast()
print(tmp1)
tmp1.lastToFirst()
print(tmp1)

出力結果
[1, 2, 3, 0]
[0, 1, 2, 3]