uicolor

cannot set custom colors for pie charts

蹲街弑〆低调 提交于 2020-06-27 16:58:12
问题 I am using iOS charts to make a pie chart, and I cannot figure out how to set the colors as custom colors with RGBA values. here is the code var colors: [UIColor] = [] colors.append(UIColor.init(red: 206, green: 173, blue: 128, alpha: 1)) colors.append(UIColor.init(red: 136, green: 169, blue: 132, alpha: 1)) colors.append(UIColor.init(red: 183, green: 73, blue: 32, alpha: 1)) colors.append(UIColor.init(red: 106, green: 152, blue: 150, alpha: 1)) colors.append(UIColor.init(red: 226, green: 120

Changing a custom UIView background when selected

↘锁芯ラ 提交于 2020-06-27 06:38:09
问题 I have three custom circle UIViews which are created. When a user clicks on one of these I would like to change the background Color of the view to be Grey. When the view is originally created, it is a randomColor. I would like this color to stay around for if the view was selected again. I.e. change from color to grey and then grey to color when selected again. What is the best way to change the view background or add an overlay in someway to my custom UIView to make it grey? 回答1: I think

Changing a custom UIView background when selected

半腔热情 提交于 2020-06-27 06:38:04
问题 I have three custom circle UIViews which are created. When a user clicks on one of these I would like to change the background Color of the view to be Grey. When the view is originally created, it is a randomColor. I would like this color to stay around for if the view was selected again. I.e. change from color to grey and then grey to color when selected again. What is the best way to change the view background or add an overlay in someway to my custom UIView to make it grey? 回答1: I think

Programmatically Lighten or Darken a hex color in dart

会有一股神秘感。 提交于 2020-06-14 07:50:07
问题 I am trying to convert this hash color code #159424 (GREEN-COLOR) to more darken and lighten programmatically. How to do this please help? make green color darker toDarkColor(String hashColor){ // how to convert that hash string to make green color darker? } make green color lighter toLightColor(String hashColor){ // how to convert that hash string to make green color lighter? } 回答1: You can use tinycolor package: TinyColor.fromString("#159424").darken(10).color Edit: You can convert Color

Changing font color of UIBarButtonItem

寵の児 提交于 2020-06-11 16:53:07
问题 I tried to change the font color of the right bar button item to purple, but it still shows up as white. I've consulted this question and this question. How do I fix this? Code let sortButton = UIButton(frame: CGRect(x: 0, y: 0, width: 34, height: 15)) sortButton.setTitle("SORT", for: .normal) sortButton.titleLabel?.tintColor = UIColor.myMusicPurple sortButton.tintColor = UIColor.myMusicPurple navigationItem.rightBarButtonItem = UIBarButtonItem(customView: sortButton) navigationItem

How to convert a String to UIColor in Swift 3.0?

爷,独闯天下 提交于 2020-05-27 06:38:19
问题 I am trying to convert an existing program which uses a list of predefined colors from Objective-C to Swift. The original code used Selector to extract a UIColor based on it name represented as a NSString #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 *)getColor:(NSString*)colorName { SEL selColor = NSSelectorFromString(colorName);

How to convert a String to UIColor in Swift 3.0?

纵然是瞬间 提交于 2020-05-27 06:35:05
问题 I am trying to convert an existing program which uses a list of predefined colors from Objective-C to Swift. The original code used Selector to extract a UIColor based on it name represented as a NSString #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 *)getColor:(NSString*)colorName { SEL selColor = NSSelectorFromString(colorName);

iOS开发技巧(系列十八:扩展UIColor,支持十六进制颜色设置)

僤鯓⒐⒋嵵緔 提交于 2020-02-28 13:54:33
新建一个Category,命名为UIColor+Hex,表示UIColor支持十六进制Hex颜色设置。 UIColor+Hex.h文件, #import <UIKit/UIKit.h> #define RGBA_COLOR(R, G, B, A) [UIColor colorWithRed:((R) / 255.0f) green:((G) / 255.0f) blue:((B) / 255.0f) alpha:A] #define RGB_COLOR(R, G, B) [UIColor colorWithRed:((R) / 255.0f) green:((G) / 255.0f) blue:((B) / 255.0f) alpha:1.0f] @interface UIColor (Hex) + (UIColor *)colorWithHexString:(NSString *)color; //从十六进制字符串获取颜色, //color:支持@“#123456”、 @“0X123456”、 @“123456”三种格式 + (UIColor *)colorWithHexString:(NSString *)color alpha:(CGFloat)alpha; @end 上面的代码在开头是两个宏定义,就是对[UIColor colorWithRed:green:blue

UIColor-subclass crashes when casting from Any?

橙三吉。 提交于 2020-02-24 12:10:08
问题 I know, subclassing UIColor isn't recommended. Apple says Most developers have no need to subclass UIColor But I do. More on why can be found from another question I posted yesterday. That particular issue was solved, but I met another problem. Let's say I have this custom color class: class MyColor:UIColor{ convenience init(test:String){ self.init(red: 0, green: 0, blue: 0, alpha: 1) } } //Then do this anywhere: let myColor = MyColor(test: "test") let temp:Any? = myColor let c = temp as!

Overriding or extending UIColor to support certain protocols

南楼画角 提交于 2020-01-24 19:39:06
问题 I'm trying to subclass or extend UIColor to support a few protocols. Let's say my protocol looks like this: public protocol MyProtocol { init(myValue: Any) throws } For some reason, I'm unable to implement it, and I don't know why. This works for all other classes: class MyTestClass:SomeOtherClass, MyProtocol{ required init(myValue: Any) throws{ super.init(someOtherClassInitializer:Any) } } No issues. But if I try to do this with UIColor, I get errors. class MyColor:UIColor, MyProtocol{