uicolor
Convert CGColor to corresponding UIColor in Swift
Get the UIColor from the CGColor using UIColor(cgColor: …): let uiColor = UIColor(cgColor: cgColor) then assign it as a background color to your button.
Change color of translucent black UINavigationBar
Once you know it, it’s fairly simple: self.navigationController.navigationBar.tintColor = [UIColor blueColor]; self.navigationController.navigationBar.alpha = 0.7f; self.navigationController.navigationBar.translucent = YES; The translucent property seems only to determine wether the main view should be visible under the navigation bar, and resizes the view appropiately.
Programmatically Lighten or Darken a hex color in dart
For people who want to darken or lighten Color instead of hex string // ranges from 0.0 to 1.0 Color darken(Color color, [double amount = .1]) { assert(amount >= 0 && amount <= 1); final hsl = HSLColor.fromColor(color); final hslDark = hsl.withLightness((hsl.lightness – amount).clamp(0.0, 1.0)); return hslDark.toColor(); } Color lighten(Color color, [double amount = .1]) … Read more
How do I make my own custom UIColor’s other than the preset ones?
You can write your own method for UIColor class using categories. #import <UIKit/UIKit.h> @interface UIColor(NewColor) +(UIColor *)MyColor; @end #import “UIColor-NewColor.h” @implementation UIColor(NewColor) +(UIColor *)MyColor { return [UIColor colorWithRed:0.0-1.0 green:0.0-1.0 blue:0.0-1.0 alpha:1.0f]; } By this way, you create a new color and now you can call it like [UIColor MyColor]; You can also implement this method … Read more
init(colorLiteralRed:,green:,blue:,alpha:) deprecated in Swift 4
init(colorLiteralRed:green:blue:alpha:) is intended to be used with Color Literals which are managed by development tools. Why don’t you use normal init(red:green:blue:alpha:)? let startingColorOfGradient = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0).cgColor let endingColorOFGradient = UIColor(red: 251.0/255.0, green: 247.0/255.0, blue: 234.0/255.0, alpha: 1.0).cgColor let gradient: CAGradientLayer = CAGradientLayer() (Writing like 234.0/255.0 is not mandatory, in … Read more
How to add initializers in extensions to existing UIKit classes such as UIColor?
You can’t do it like this, you have to chose different parameter names to create your own initializers/ You can also make then generic to accept any BinaryInteger or BinaryFloatingPoint types: extension UIColor { convenience init<T: BinaryInteger>(r: T, g: T, b: T, a: T = 255) { self.init(red: .init(r)/255, green: .init(g)/255, blue: .init(b)/255, alpha: .init(a)/255) … Read more