Added hexString property for UIColor

This commit is contained in:
Ivan Babkin 2019-04-25 15:18:19 +03:00
parent 0df9be960f
commit ddd008398f
7 changed files with 29 additions and 5 deletions

View File

@ -1,5 +1,8 @@
# Changelog
### 0.9.18
- **Add**: `hexString` property for `UIColor` that returns hex representation of color as string.
### 0.9.17
- **Fix**: SpinnerView infinity animation.

View File

@ -27,7 +27,7 @@ import UIKit
public typealias SearchResultsController = UIViewController & SearchResultsViewController
/// Class that allows to enter text for search and then displays search results in table view
open class BaseSearchViewController<Item,
open class BaseSearchViewController < Item,
ItemViewModel,
ViewModel,
CustomView: UIView & TableViewHolder>: BaseCustomViewController<ViewModel, CustomView>

View File

@ -126,3 +126,24 @@ public extension UIColor {
}
}
}
public extension UIColor {
/// Hex representation of UIColor as String
var hexString: String {
var red: CGFloat = 0
var green: CGFloat = 0
var blue: CGFloat = 0
var alpha: CGFloat = 0
getRed(&red, green: &green, blue: &blue, alpha: &alpha)
let intRepresentation = alpha == 1
? Int(red * 255) << 16 | Int(green * 255) << 8 | Int(blue * 255) << 0
: Int(red * 255) << 24 | Int(green * 255) << 16 | Int(blue * 255) << 8 | Int(alpha * 255) << 0
return alpha == 1
? String(format: "#%06x", intRepresentation)
: String(format: "#%08x", intRepresentation)
}
}

View File

@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.9.17</string>
<string>0.9.18</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>

View File

@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.9.17</string>
<string>0.9.18</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>

View File

@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.9.17</string>
<string>0.9.18</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>

View File

@ -102,7 +102,7 @@ private extension ApiUploadRequestParameters {
fileExtension as CFString,
nil)?.takeRetainedValue(),
let mimeType = UTTypeCopyPreferredTagWithClass(utiType,
kUTTagClassMIMEType)?.takeRetainedValue() as? String else {
kUTTagClassMIMEType)?.takeRetainedValue() as String? else {
assertionFailure("Unable to get mime type from file name")
throw UploadParametersError.unableGetMimeType