How can I create a UIColor
from a hexadecimal string format, such as #00FF00
?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Xcode: Is there a way to change line spacing (UI L
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
You can make a extension like this
And use it anywhere like this
This is a function that takes a hex string and returns a UIColor.
(You can enter hex strings with either format:
#ffffff
orffffff
)Usage:
Swift 4:
Swift 3:
Swift 2:
Source: arshad/gist:de147c42d7b3063ef7bc
You can use this library
https://github.com/burhanuddin353/TFTColor
Swift
Objective-C
Use this Category :
in the file UIColor+Hexadecimal.h
in the file UIColor+Hexadecimal.m
In Class you want use it :
and:
SWIFT 4
You can create a nice
convenience
constructor in the extension like this:And use it later like
There is no builtin conversion from a hexadecimal string to a
UIColor
(orCGColor
) that I'm aware of. However, you can easily write a couple of functions for this purpose - for example, see iphone development accessing uicolor components