I\'m creating custom elements in my app and want to match the look and feel of the new iOS. iOS 7 introduced to us a very common lighter blue color, the default color or tin
Get the color automatically by using this code:
static let DefaultButtonColor = UIButton(type: UIButtonType.System).titleColorForState(.Normal)!
The UIWindow.tintColor
method wasn't working for me in iOS8 (it was still black), so I had to do this:
let b = UIButton.buttonWithType(UIButtonType.System) as UIButton
var color = b.titleColorForState(.Normal)
This gave the proper blue tint seen in a UIBarButtonItem
Use self.view.tintColor
from a view controller, or self.tintColor
from a UIView
subclass.
Hex Color code
#007AFF
and you need this libary https://github.com/thii/SwiftHEXColors
ps. iOS, Swift
Please don't mess with view.tintColor
or extensions, but simply use this:
UIColor.systemBlue
This extension gives you native system blue color.
extension UIColor {
static var systemBlue: UIColor {
return UIButton(type: .system).tintColor
}
}
UPDATE
Please forget what I wrote above, just figured out - there're native extension with predefined system colors we've been looking for, including system blue:
// System colors
extension UIColor {
/* Some colors that are used by system elements and applications.
* These return named colors whose values may vary between different contexts and releases.
* Do not make assumptions about the color spaces or actual colors used.
*/
...
@available(iOS 7.0, *)
open class var systemBlue: UIColor { get }
...
}
You can use it directly:
myView.tintColor = .systemBlue