code from http://www.weheartswift.com/make-awesome-ui-components-ios-8-using-swift-xcode-6/