使用 [UIColor colorWithRed:green:blue:alpha:] 不适用于 UITableView 分隔符颜色? [英] Using [UIColor colorWithRed:green:blue:alpha:] doesn't work with UITableView seperatorColor?

查看:10
本文介绍了使用 [UIColor colorWithRed:green:blue:alpha:] 不适用于 UITableView 分隔符颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试配置深灰色分隔符颜色.为什么以下什么都不做?

I'm trying to configure a dark gray seperator color. Why does the following do nothing?

self.tableView.seperatorStyle = UITableViewCellSeperatorStyleSingleLine;
self.tableView.seperatorColor = [UIColor colorWithRed: 127 green:127 blue:127 alpha:1];

返回一个完全没有分隔符的表.

returns a table with no seperators at all.

只要我使用 [UIColor blackColor],我就可以得到分隔符.有什么关系?

As soon as I use [UIColor blackColor] then I get seperators just fine. What's the deal?

推荐答案

需要除以255.0

因为我几乎不使用介于 1.0 和 0.0 之间的值,所以我创建了一个非常简单的 UIColor 类别,它自己完成看起来凌乱的划分:(来自 http://github.com/Jon889/JPGeneral)

Because I hardly ever use values between 1.0 and 0.0, I created a very simple UIColor category that does the messy looking division by itself: (from http://github.com/Jon889/JPGeneral)

//.h file
@interface UIColor (JPExtras)
+ (UIColor *)colorWithR:(CGFloat)red G:(CGFloat)green B:(CGFloat)blue A:(CGFloat)alpha;
@end

//.m file
@implementation UIColor (JPExtras)
+ (UIColor *)colorWithR:(CGFloat)red G:(CGFloat)green B:(CGFloat)blue A:(CGFloat)alpha {
    return [UIColor colorWithRed:(red/255.0) green:(green/255.0) blue:(blue/255.0) alpha:alpha];
}
@end

所以你可以这样做(如果你导入我上面链接的类别):

So you can just do(If you import the category I linked to above):

[UIColor colorWithR:127 G:127: B:127 A:1];

这篇关于使用 [UIColor colorWithRed:green:blue:alpha:] 不适用于 UITableView 分隔符颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆