UIColor+Hex, now Swift
  • March 11, 2024

Convenience method for creating autoreleased color using RGBA hex string.


 

// Solid color
let strokeColor = UIColor(“#FFCC00”).cgColor

// Color with alpha
let fillColor = UIColor(“#FFCC00DD”).cgColor

// Supports shorthand 3 character representation
let backgroundColor = UIColor(“#FFF”)

// Supports shorthand 4 character representation (with alpha)
let menuTextColor = UIColor(“#013E”)

// “#FF0000FF”
let hexString = UIColor.red.hexString()

// Convert shorthand 4 character representation (with alpha) from argb to rgba
if let rgba = “#AFFF”.argb2rgba {
let androidBackgroundColor = UIColor(rgba)
}

// Convert 8 character representation (with alpha) from argb to rgba
if let rgba = “#AAFFFFFF”.argb2rgba {
let androidFrontColor = UIColor(rgba)
}

Release Notes


  • Upgrade to Swift 5.
  • macOS gets supported.

Installation


To add a package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and enter https://github.com/yeahdongcn/UIColor-Hex-Swift to the text field.

Simply add the following lines to your Podfile:

# required by CocoaPods 0.36.0.rc.1 for Swift Pods
use_frameworks!

pod ‘UIColor_Hex_Swift’, ‘~> 5.1.9’

Then import it where you use it:

import UIColor_Hex_Swift

(CocoaPods v0.36 or later required. See this blog post for details.)

Simply add the following line to your Cartfile:

github “yeahdongcn/UIColor-Hex-Swift” >= 5.1.9

Then add the HexColor.framework to your frameworks list in the Xcode project.

Then import it where you use it:

import HEXColor

GitHub


View Github

#backgroundcolor #color #colorpicker #colorpickerview #material-colors
YOU MIGHT ALSO LIKE...
exyte

     

camerakit-ios

CameraKit helps you add reliable camera to your app quickly. Our open source camera platform provides consistent capture results, service ...

HybridCamera

[video width="192" height="416" mp4="https://swiftgit.com/wp-content/uploads/2024/12/68747470733a2f2f7261776769742e636f6d2f7374796c656b69742f696d672f6d61737465722f7669645f6564697465645f325f326d622e676966.mp4"][/video]

TakeASelfie

An iOS framework that uses the front camera, detects your face and takes a selfie. This api opens the front ...

iOS-Depth-Sampler

Code examples of Depth APIs in iOS