UIColor colorWithString给我一个错误iOS



这是我试图更新的一个旧项目。我在使用UIColor colorWithString的每一行都会出现错误。我是个新手,所以即使我查过CIColor和colorWithHex,我似乎也无法让它发挥作用。有什么想法吗?

`UILabel *versionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 40, 320, 20)];
versionLabel.backgroundColor = [UIColor clearColor];
versionLabel.textColor = [UIColor whiteColor];
versionLabel.textAlignment = NSTextAlignmentCenter;
versionLabel.text = NSStringf(@"v%@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]);
versionLabel.font = [self customFontWithSize:10];
versionLabel.textColor = [UIColor colorWithString:@"9fb4cs"];`
colorWithString

不是UIColor 的标准方法

看起来你在使用UIColor类别来扩展内置功能,可能是ColorUtils

这仍然被项目引用吗?它是否包含在您的源文件中?

来自您正在使用的非标准类别ColorUtils的文档。

十六进制字符串可以以#、0x或无前缀,并且可以有3、6或8位数字。6位数字是标准的rrggbb格式,8位是相同的,但有一个alpha组件,3位是CSS中常用的缩写,其中每个十六进制数字都是重复的,因此#29f变成#22299ff。

所以把你的最后一行改成

versionLabel.textColor = [UIColor colorWithString:@"#9fb4cs"];

显然,这是一个旧组件,我切换到colorwithRGBA,并使用此转换器为我提供rgb值http://www.javascripter.net/faq/hextorgb.htm

相关内容

最新更新