Skip to content

Instantly share code, notes, and snippets.

@rickyngan
rickyngan / dateFormatter.swift
Created September 21, 2016 06:19 — forked from m1entus/dateFormatter.swift
Swift NSDateFormatter singleton
class var userDateFormatter : NSDateFormatter {
struct Static {
static let instance: NSDateFormatter = {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
return dateFormatter
}()
}
return Static.instance
}
extension UIColor {
convenience init(rgb: UInt) {
self.init(
red: CGFloat((rgb & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgb & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgb & 0x0000FF) / 255.0,
alpha: CGFloat(1.0)
)
}
}
let labelHeight = self.addressLabel.intrinsicContentSize().height
self.mapView.padding = UIEdgeInsets(top: self.topLayoutGuide.length, left: 0,
bottom: labelHeight, right: 0)
UIView.animateWithDuration(0.25) {
//2
self.pinImageVerticalConstraint.constant = ((labelHeight - self.topLayoutGuide.length) * 0.5)
self.view.layoutIfNeeded()
}
@rickyngan
rickyngan / ViewController.swift
Last active May 25, 2018 19:25
LoginButton enable when both username and password textfields are filled.
loginUserNameTextField.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .editingChanged)
loginUserPasswordTextField.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .editingChanged)
@objc func textFieldDidChange(_ textField: UITextField) {
loginButton.enabled = loginUserNameTextField.text.length && loginUserPasswordTextField.text.length
}