UIColor colorWithRed:green:blue:alpha: always returns white unless one argument is 0
The parameter aren't a values of 0 to 255 but a float between 0.0 and 1.0:
[UIColor colorWithRed:0.0f/255.0f green:155.0f/255.0f blue:218.0f/255.0f alpha:1.0f];
fill border rect with custom color
The arguments for custom RGB codes must be CGFloats.
UIColor* color = [UIColor colorWithRed:80.0/255.0 green:80.0/255.0 blue:80.0/255.0 alpha:1];
would be the correct way to specify your custom RGB color
background color not working as expected
The arguments for colorWithRed:green:blue:alpha
need to be CGFloat
s on a scale from 0 to 1, where 0 is 0 and 1 is 255. Therefore, your code should look more like this:
UIColor *color = [UIColor colorWithRed:76.0/255.0
green:76.0/255.0
blue:76.0/255.0
alpha:1.0];
Swift border color
The input values needs to be between 0 and 1, so divide them by 255.
buyButton.layer.borderColor = UIColor(red: 83.0/255.0, green: 186.0/255.0, blue: 183.0/255.0, alpha: 1.0).cgColor
How do I get red green blue (RGB) and alpha back from a UIColor object?
The reason for the crash when accessing SelectedColor.CGColor
could be that you do not retain the result from getColor
, perhaps what you need is:
SelectedColor = [[(ColorPickerView *)alertView getColor] retain];
You can only get the RGB color component from a UIColor
that is using the RGB color space, since you are using colorWithRed:green:blue:alpha:
that is not a problem, but be vary of this if your code changes.
With this is mind getting the color components is really easy:
const CGFloat* components = CGColorGetComponents(SelectedColor.CGColor);
NSLog(@"Red: %f", components[0]);
NSLog(@"Green: %f", components[1]);
NSLog(@"Blue: %f", components[2]);
NSLog(@"Alpha: %f", CGColorGetAlpha(SelectedColor.CGColor));
Related Topics
Not Receiving Push Notifications from Firebase
iOS Timed Background Processing
Increment Uislider by 1 in Range 1 to 100
How to Broadcast Multiple Ibeacon Signals from Only One Bluetooth? and How
Best Way to Use Background Location Updates in iOS (Swift)
Alamofire Fire Variable Type Has No Subscript Members
How to Install an Unsigned IPA File on My Device Using an Apple Developer Account
Audiokit: Using the New Aksequencer with Any Variety of the Callback Instruments
Saving and Loading Up a Highscore in Swift Using Nsuserdefaults
How Get the List of Errors Thrown by a Function
Enable and Debug Zombie Objects in iOS Using Xcode 5.1.1
How to Integrate Crashlytics into an iOS Framework Target
Swift Compatibility Between Versions for a Library
Pod Install Command with Error