- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下类别扩展 UIColor
:
.h
#import <UIKit/UIKit.h>
@interface UIColor (Colors)
- (NSArray *)reds;
@end
#import "UIColor+Colors.h"
@implementation UIColor (Colors)
- (NSArray *)reds {
return [[NSArray alloc] initWithObjects:[UIColor colorWithRed:1.0/255.0 green:50.0/255.0 blue:98.0/255.0 alpha:1],[UIColor colorWithRed:1.0/255.0f green:37.0f/255.0f blue:75.0f/255.0f alpha:1],[UIColor colorWithRed:1.0/255.0 green:1.0/255.0 blue:52.0/255.0 alpha:1],[UIColor colorWithRed:90.0/255.0 green:13.0/255.0 blue:1.0/255.0 alpha:1],[UIColor colorWithRed:53.0/255.0 green:6.0/255.0 blue:1.0/255.0 alpha:1], nil];
}
@end
[cell setBackgroundColor:[UIColor reds][0]];
知道我做错了什么吗?
最佳答案
我认为最可能的问题是函数 reds
必须是类方法才能调用 reds
在类里面。所以是这样的:
。H
@interface UIColor (Colors)
+(NSArray *)reds;
@end
@implementation UIColor (Colors)
+(NSArray *)reds {
return @[[UIColor colorWithRed:1.0/255.0 green:50.0/255.0 blue:98.0/255.0 alpha:1],
[UIColor colorWithRed:1.0/255.0f green:37.0f/255.0f blue:75.0f/255.0f alpha:1],
[UIColor colorWithRed:1.0/255.0 green:1.0/255.0 blue:52.0/255.0 alpha:1],
[UIColor colorWithRed:90.0/255.0 green:13.0/255.0 blue:1.0/255.0 alpha:1],
[UIColor colorWithRed:53.0/255.0 green:6.0/255.0 blue:1.0/255.0 alpha:1]];
}
@end
+
而不是
-
.如果您使用
-
它是一个实例方法,因此您必须实例化 UIColor 的实例才能调用
reds
.
关于ios - 返回 uicolors 数组的类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27789731/
我正在为 UIColor 编写一个简单的扩展,以获取基于 this answer 的十六进制字符串: import UIKit extension UIColor { public stati
例如,下面的代码与 UIColor.Purple 或 UIColor.Yellow 一起工作正常,但当我使用 UIColor.black 时应用程序崩溃。 fatal error :索引超出范围使用
这个颜色 [UIColor colorWithRed:75.0/255.0 green:215.0/255.0 blue:100.0/
使用 self.backgroundColor = .init(named: "my-color") 其中 self 是一个 UIView,触发此错误: Value of optional type
我正在尝试使用以下代码创建一个 UIColor 实例: var someColor:UIColor = UIColor.colorWithAlphaComponent(0.3) 预编译器告诉我有错误。
我有一个带有 UIColor 属性的对象: class Beer: NSObject { var color: UIColor? ... } 我正在将其保存到数据库中,因此我需要将此属性转换为
这个问题已经有答案了: Swift UIColor initializer - compiler error only when targeting iPhone5s (2 个回答) 已关闭 8 年前
我在 View Controller 类中设置标签颜色。当我使用以下代码时,它起作用了。 self.labelTest.textColor = UIColor.red 但是,如果我使用 UIColor
我想在饼图中提供自定义颜色(使用图表 Pane )。但是为此,setColors([NSUIColor]) 中的数组需要 NSUIColor 格式的颜色数组,我有颜色的十六进制代码。如何使用十六进制代
我正在尝试从 rgb-hex 色彩空间实现 CIColor,如下所示: let bottomColor = UIColor.init(red: 235/255, green: 250/255,
在我的应用程序中,我尝试使用不同的颜色进行绘制。我有自己的颜色选择器,但我想将颜色亮度添加到此选择器 slider 。对于 understudying :我选择一种颜色显示在 View 中的某个地方作
UILabel label = new UILabel(); label.TextColor = UIColor.Black; 如何以字符串格式存储 UILabel 颜色?我想从数据库中获取该颜色并
我无法从使用工厂方法创建的 UIColor(带有模式)创建 NSData 对象 [UIColor colorWithPatternImage:image] 适用于标准 UIColor 对象。想知道是否
我在将 uicolor 转换为十六进制颜色时遇到问题,这是我发现的 CGColorRef colorref = [[Colorview_ backgroundColor] CGColor]; int
我正在绘制一个饼图,每个切片都有不同的颜色。我需要给切片带来纹理外观,而不仅仅是纯色。有什么想法如何做到这一点?我不想使用图像作为所有可能颜色的纹理。所以我需要生成纹理或类似的东西。有任何想法吗。谢谢
我有一个十六进制颜色值,我想将其转换为 UIColor。 UIColor 可以接受色相/饱和度/亮度 (HSB) 值或红/蓝/绿 (RGB) 值。如何使用十六进制值创建 UIColor? 最佳答案 有
我正在涉足 Android 的 MonoTouch/Mono,目前正在创建我自己的 UIColor 子类。不知何故,我无法让我的工厂方法以我想要的方式工作(但我确实有一个解决方法)。 以下代码导致我崩
我已经构建了一组自定义颜色以在我的应用程序中使用,例如石灰 mylimeColor = [UIColor colorWithRed:0.502 green:1.000 blue:0.000 alpha
我正在制作一个交互式应用程序,它应该显示一个蓝色的 UILabel,当按下某个按钮时它必须消失。当我们继续按下按钮时,标签的颜色应该会褪色。我尝试创建自定义 UIColor 并更改其亮度,但效果并不理
尝试简化每个单元格行对象着色的实现。这就是我当前向每行中的对象添加颜色的方式: progressViewLeft.primaryColor = Colors.Stage1 “Colors”是一个像这样
我是一名优秀的程序员,十分优秀!