UIColor not working with RGBA values

RGB values for UIColor are between 0 and 1 (see the documentation “specified as a value from 0.0 to 1.0”) You need to divide your numbers by 255: passwordTextField.textColor = UIColor(red: CGFloat(202.0/255.0), green: CGFloat(228.0/255.0), blue: CGFloat(230.0/255.0), alpha: CGFloat(1.0)) Another thing, you don’t need to create CGFloats: passwordTextField.textColor = UIColor(red:202.0/255.0, green:228.0/255.0, blue:230.0/255.0, alpha:1.0)

How can I change image tintColor in iOS and WatchKit

iOS For an iOS app, in Swift 3, 4 or 5: theImageView.image = theImageView.image?.withRenderingMode(.alwaysTemplate) theImageView.tintColor = UIColor.red For Swift 2: theImageView.image = theImageView.image?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate) theImageView.tintColor = UIColor.redColor() Meanwhile, the modern Objective-C solution is: theImageView.image = [theImageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; [theImageView setTintColor:[UIColor redColor]]; Watchkit In WatchKit for Apple Watch apps, you can set the tint color for a template … Read more

How can I create a UIColor from a hex string?

I’ve found the simplest way to do this is with a macro. Just include it in your header and it’s available throughout your project. #define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] uicolor macro with hex values Also formatted version of this code: #define UIColorFromRGB(rgbValue) \ … Read more

How to change the status bar background color and text color on iOS 7?

Warning: It does not work anymore with iOS 13 and Xcode 11. ======================================================================== I had to try look for other ways. Which does not involve addSubview on window. Because I am moving up the window when keyboard is presented. Objective-C – (void)setStatusBarBackgroundColor:(UIColor *)color { UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@”statusBarWindow”] valueForKey:@”statusBar”]; if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) { … Read more

Saving UIColor to and loading from NSUserDefaults

One way of doing it might be to archive it (like with NSColor, though I haven’t tested this): NSData *colorData = [NSKeyedArchiver archivedDataWithRootObject:color]; [[NSUserDefaults standardUserDefaults] setObject:colorData forKey:@”myColor”]; And to get it back: NSData *colorData = [[NSUserDefaults standardUserDefaults] objectForKey:@”myColor”]; UIColor *color = [NSKeyedUnarchiver unarchiveObjectWithData:colorData];

How to use hex color values

#ffffff are actually 3 color components in hexadecimal notation – red ff, green ff and blue ff. You can write hexadecimal notation in Swift using 0x prefix, e.g 0xFF To simplify the conversion, let’s create an initializer that takes integer (0 – 255) values: extension UIColor { convenience init(red: Int, green: Int, blue: Int) { … Read more