![]() If you wanted it always to return a value, change init? to be init then change the return nil line at the end to be return UIColor.black or whatever you'd like the default value to be. Self.init(red: r, green: g, blue: b, alpha: a) Let start = hex.index(hex.startIndex, offsetBy: 1) It should be a # symbol, followed by red, green, blue and alpha in hex format, for a total of nine characters. In the Color section, change the input method to 8-bit Hexadecimal. In the name field, set the name to DarkGreen. Then click the Attributes inspector icon to reveal the attributes of a color set. ![]() Next, choose the color well and click the Show inspector button. ![]() The new method is a failable initializer, which means it returns nil if you don't specify a color in the correct format. Right click the blank area (under AppIcon) and select New Color Set. Here's a simple extension to UIColor that lets you create colors from hex strings.
0 Comments
Leave a Reply. |