Making RGB color in Xcode
Objective-C
You have to give the values between 0 and 1.0. So divide the RGB values by 255.
myLabel.textColor= [UIColor colorWithRed:(160/255.0) green:(97/255.0) blue:(5/255.0) alpha:1] ;
Update:
You can also use this macro
#define Rgb2UIColor(r, g, b) [UIColor colorWithRed:((r) / 255.0) green:((g) / 255.0) blue:((b) / 255.0) alpha:1.0]
and you can call in any of your class like this
myLabel.textColor = Rgb2UIColor(160, 97, 5);
Swift
This is the normal color synax
myLabel.textColor = UIColor(red: (160/255.0), green: (97/255.0), blue: (5/255.0), alpha: 1.0)
//The values should be between 0 to 1
Swift is not much friendly with macros
Complex macros are used in C and Objective-C but have no counterpart
in Swift. Complex macros are macros that do not define constants,
including parenthesized, function-like macros. You use complex macros
in C and Objective-C to avoid type-checking constraints or to avoid
retyping large amounts of boilerplate code. However, macros can make
debugging and refactoring difficult. In Swift, you can use functions
and generics to achieve the same results without any compromises.
Therefore, the complex macros that are in C and Objective-C source
files are not made available to your Swift code.
So we use extension for this
extension UIColor {
convenience init(_ r: Double,_ g: Double,_ b: Double,_ a: Double) {
self.init(red: r/255, green: g/255, blue: b/255, alpha: a)
}
}
You can use it like
myLabel.textColor = UIColor(160.0, 97.0, 5.0, 1.0)
Add a custom color palette to Xcode Interface Builder
Yes, you can create and edit a palette in IB and then share it with your team This article has all the details: http://natashatherobot.com/xcode-color-palette/
Edit:
That link has expired. You can see the web archive here: https://web.archive.org/web/20210303015055/http://natashatherobot.com/xcode-color-palette/
But, using named colors in the asset catalog is a better way to go now.
How can I use UIColorFromRGB in Swift?
Here's a Swift version of that function (for getting a UIColor representation of a UInt
value):
func UIColorFromRGB(rgbValue: UInt) -> UIColor {
return UIColor(
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
alpha: CGFloat(1.0)
)
}
view.backgroundColor = UIColorFromRGB(0x209624)
How to set custom color in the view controller's background
Simply:
self.view.backgroundColor = UIColor(red: 178/255, green: 178/255, blue: 122/255, alpha: 1)
The rgb
values are equal to #B2B27A
.
Edit:
You can also add an hex/rgb value in your Storyboard:
- Select your view
- Click background in attributes inspector
- Select the second menu item in the colors window
How do I enter RGB values into Interface Builder?
Click on the color slider icon, and then choose "RGB Sliders" from the drop-down list.
You can also use the magnifying-glass as a color picker to pick up an exact color from anywhere on the screen; also see @ken's excellent comment below clarifying how colorspaces work with the magnifying glass.
set color of any UI in RGB format
It should be like this
[_sliderSpeed setMaximumTrackTintColor:[UIColor colorWithRed:(181/255.0) green:(217/255.0) blue:(255/255.0) alpha:1] ;//set your color here
For Ref:
https://stackoverflow.com/a/10379026
How to add custom color in Xcode storyboard color picker?
Create a new palette by clicking "New" here:
A new palette "Unnamed" will be created. You can rename that palette by clicking the cog again and choosing "Rename..." Then, you'll need to click on the objects you want to capture the color of, and drag the color of those objects into the color chip area:
Once you've captured the color, you can even rename it something that indicates where it's normally used, providing more information to the recipient than just the color.
source
How to get RGB components of a custom color in ios
You can use the DigitalColor Meter.app included with every Mac OS X install. You can find it in ~/Applications/Utilities/DigitalColor Meter.app
. Use it to inspect the RGB values of any pixel you mouse over. Once you have the values, you just need to divide them by 255.0
because +colorWithRed:green:blue:alpha:
is expecting a floating point value between 0 and 1.
[UIColor colorWithRed:83.0f/255.0f green:217.0f/255.0f blue:58.0f/255.0f alpha:1.0f];
Related Topics
Alert View Is Showing White Rectangle in iOS7
"No Such Module 'Alamofire'" Xcode Won't Recognize Alamofire Framework
Dismissing Both Uinavigation Views and Modal Views at Once Programmatically
Mkmapview Show Incorrectly Saved Region
Convert Request Function to Generic Type
How to Do a Native "Pulse Effect" Animation on a Uibutton - iOS
Uirefreshcontrol on Uicollectionview Only Works If the Collection Fills the Height of the Container
Arkit Hide Objects Behind Walls
Check If Location Services Are Enabled
Uirefreshcontrol with Uicollectionview in iOS7
Set Uitableview's Height to the Height of Its Content with Auto Layout
An Error Occurred Uploading to the Itunes Store
How to Have a Dynamic List of Views Using Swiftui
Converting Nsdictionary Object to Nsdata Object and Vice-Versa
How to Get the iOS Device CPU Architecture in Runtime
"Could Not Find Developer Disk Image"
Hide Device Volume Hud View While Adjusitng Volume with Mpvolumeview Slider