Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ios可选4种颜色_Ios_Objective C - Fatal编程技术网

ios可选4种颜色

ios可选4种颜色,ios,objective-c,Ios,Objective C,我试着给4个细胞不同的颜色,然后重复。(所以不是斑马样式的表,而是使用4) 为什么这不起作用? 我只有两种颜色 if (indexPath.row % 4 == 0) [cell setColor:[UIColor colorFromHexString:@"35a8e1"]]; if (indexPath.row % 4 == 1) [cell setColor:[UIColor colorFromHexString:@"5cb14c"]]; if (indexPath.row

我试着给4个细胞不同的颜色,然后重复。(所以不是斑马样式的表,而是使用4) 为什么这不起作用? 我只有两种颜色

if (indexPath.row % 4 == 0)
    [cell setColor:[UIColor colorFromHexString:@"35a8e1"]];
if (indexPath.row % 4 == 1)
    [cell setColor:[UIColor colorFromHexString:@"5cb14c"]];
if (indexPath.row % 4 == 2)
    [cell setColor:[UIColor colorFromHexString:@"ec292d"]];
else
    [cell setColor:[UIColor colorFromHexString:@"ee8c1d"]];




+(UIColor*)colorFromHexString:(NSString*)hex
{
    NSString *cString = [[hex stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];

    // String should be 6 or 8 characters
    if ([cString length] < 6) return [UIColor grayColor];

    // strip 0X if it appears
    if ([cString hasPrefix:@"0X"]) cString = [cString substringFromIndex:2];

    if ([cString length] != 6) return  [UIColor grayColor];

    // Separate into r, g, b substrings
    NSRange range;
    range.location = 0;
    range.length = 2;
    NSString *rString = [cString substringWithRange:range];

    range.location = 2;
    NSString *gString = [cString substringWithRange:range];

    range.location = 4;
    NSString *bString = [cString substringWithRange:range];

    // Scan values
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];

    return [UIColor colorWithRed:((float) r / 255.0f)
                           green:((float) g / 255.0f)
                            blue:((float) b / 255.0f)
                           alpha:1.0f];
}
if(indexath.row%4==0)
[单元格设置颜色:[uicolorFromHexString:@“35a8e1”];
if(indexath.row%4==1)
[单元格设置颜色:[uicolorFromHexString:@“5cb14c”];
if(indexath.row%4==2)
[单元格设置颜色:[uicolorFromHexString:@“ec292d”];
其他的
[单元格设置颜色:[uicolorFromHexString:@“ee8c1d”];
+(UIColor*)colorFromHexString:(NSString*)十六进制
{
NSString*cString=[[hex stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]大写字符串];
//字符串应为6或8个字符
if([cString length]<6)返回[UIColor grayColor];
//如果出现,请删除0X
如果([cString hasPrefix:@“0X]”)cString=[cString substringFromIndex:2];
如果([cString length]!=6)返回[UIColor grayColor];
//分为r、g、b子串
NSRange范围;
range.location=0;
range.length=2;
NSString*rString=[cString substringWithRange:range];
range.location=2;
NSString*gString=[cString substringWithRange:range];
range.location=4;
NSString*bString=[cString substringWithRange:range];
//扫描值
无符号整数r,g,b;
[[NSScanner scannerWithString:rsString]scanHexInt:&r];
[[NSScanner scannerWithString:gString]scanHexInt:&g];
[[NSScanner SCANNER WITHSTRING:bString]scanHexInt:&b];
返回[UIColor COLOR WITHRED:((浮动)r/255.0f)
绿色:((浮动)g/255.0f)
蓝色:((浮动)b/255.0f)
α:1.0f];
}
试试看:

if (indexPath.row % 4 == 0)
    [cell setColor:[UIColor colorFromHexString:@"35a8e1"]];
else if (indexPath.row % 4 == 1)
    [cell setColor:[UIColor colorFromHexString:@"5cb14c"]];
else if (indexPath.row % 4 == 2)
    [cell setColor:[UIColor colorFromHexString:@"ec292d"]];
else
    [cell setColor:[UIColor colorFromHexString:@"ee8c1d"]];
试试看:

if (indexPath.row % 4 == 0)
    [cell setColor:[UIColor colorFromHexString:@"35a8e1"]];
else if (indexPath.row % 4 == 1)
    [cell setColor:[UIColor colorFromHexString:@"5cb14c"]];
else if (indexPath.row % 4 == 2)
    [cell setColor:[UIColor colorFromHexString:@"ec292d"]];
else
    [cell setColor:[UIColor colorFromHexString:@"ee8c1d"]];
试试看:

if (indexPath.row % 4 == 0)
    [cell setColor:[UIColor colorFromHexString:@"35a8e1"]];
else if (indexPath.row % 4 == 1)
    [cell setColor:[UIColor colorFromHexString:@"5cb14c"]];
else if (indexPath.row % 4 == 2)
    [cell setColor:[UIColor colorFromHexString:@"ec292d"]];
else
    [cell setColor:[UIColor colorFromHexString:@"ee8c1d"]];
试试看:

if (indexPath.row % 4 == 0)
    [cell setColor:[UIColor colorFromHexString:@"35a8e1"]];
else if (indexPath.row % 4 == 1)
    [cell setColor:[UIColor colorFromHexString:@"5cb14c"]];
else if (indexPath.row % 4 == 2)
    [cell setColor:[UIColor colorFromHexString:@"ec292d"]];
else
    [cell setColor:[UIColor colorFromHexString:@"ee8c1d"]];

我将实施以下措施,以便更容易推断实际发生的情况:

NSUInteger index = indexPath.row;

if (index % 4 == 0) {
    [cell setColor:[UIColor colorFromHexString:@"35a8e1"]];
} else if (index % 4 == 1) {
    [cell setColor:[UIColor colorFromHexString:@"5cb14c"]];
} else if (index % 4 == 2) {
    [cell setColor:[UIColor colorFromHexString:@"ec292d"]];
} else {
    [cell setColor:[UIColor colorFromHexString:@"ee8c1d"]];
}
当以这种方式编写时,您的代码只能执行一个操作

另外,我将在第一条if语句上设置一个断点,并逐步遍历整个语句,以查看执行的是哪条语句


或者,使用switch语句可能会让事情更清楚一些:

 switch (indexPath.row % 4) {
 case 0:
      [cell setColor:[UIColor colorFromHexString:@"35a8e1"]];
      break;
 case 1:
      [cell setColor:[UIColor colorFromHexString:@"5cb14c"]];
      break;
 case 2:
      [cell setColor:[UIColor colorFromHexString:@"ec292d"]];
      break;
 case 3:
      [cell setColor:[UIColor colorFromHexString:@"ee8c1d"]];
      break;
}

我将实施以下措施,以便更容易推断实际发生的情况:

NSUInteger index = indexPath.row;

if (index % 4 == 0) {
    [cell setColor:[UIColor colorFromHexString:@"35a8e1"]];
} else if (index % 4 == 1) {
    [cell setColor:[UIColor colorFromHexString:@"5cb14c"]];
} else if (index % 4 == 2) {
    [cell setColor:[UIColor colorFromHexString:@"ec292d"]];
} else {
    [cell setColor:[UIColor colorFromHexString:@"ee8c1d"]];
}
当以这种方式编写时,您的代码只能执行一个操作

另外,我将在第一条if语句上设置一个断点,并逐步遍历整个语句,以查看执行的是哪条语句


或者,使用switch语句可能会让事情更清楚一些:

 switch (indexPath.row % 4) {
 case 0:
      [cell setColor:[UIColor colorFromHexString:@"35a8e1"]];
      break;
 case 1:
      [cell setColor:[UIColor colorFromHexString:@"5cb14c"]];
      break;
 case 2:
      [cell setColor:[UIColor colorFromHexString:@"ec292d"]];
      break;
 case 3:
      [cell setColor:[UIColor colorFromHexString:@"ee8c1d"]];
      break;
}

我将实施以下措施,以便更容易推断实际发生的情况:

NSUInteger index = indexPath.row;

if (index % 4 == 0) {
    [cell setColor:[UIColor colorFromHexString:@"35a8e1"]];
} else if (index % 4 == 1) {
    [cell setColor:[UIColor colorFromHexString:@"5cb14c"]];
} else if (index % 4 == 2) {
    [cell setColor:[UIColor colorFromHexString:@"ec292d"]];
} else {
    [cell setColor:[UIColor colorFromHexString:@"ee8c1d"]];
}
当以这种方式编写时,您的代码只能执行一个操作

另外,我将在第一条if语句上设置一个断点,并逐步遍历整个语句,以查看执行的是哪条语句


或者,使用switch语句可能会让事情更清楚一些:

 switch (indexPath.row % 4) {
 case 0:
      [cell setColor:[UIColor colorFromHexString:@"35a8e1"]];
      break;
 case 1:
      [cell setColor:[UIColor colorFromHexString:@"5cb14c"]];
      break;
 case 2:
      [cell setColor:[UIColor colorFromHexString:@"ec292d"]];
      break;
 case 3:
      [cell setColor:[UIColor colorFromHexString:@"ee8c1d"]];
      break;
}

我将实施以下措施,以便更容易推断实际发生的情况:

NSUInteger index = indexPath.row;

if (index % 4 == 0) {
    [cell setColor:[UIColor colorFromHexString:@"35a8e1"]];
} else if (index % 4 == 1) {
    [cell setColor:[UIColor colorFromHexString:@"5cb14c"]];
} else if (index % 4 == 2) {
    [cell setColor:[UIColor colorFromHexString:@"ec292d"]];
} else {
    [cell setColor:[UIColor colorFromHexString:@"ee8c1d"]];
}
当以这种方式编写时,您的代码只能执行一个操作

另外,我将在第一条if语句上设置一个断点,并逐步遍历整个语句,以查看执行的是哪条语句


或者,使用switch语句可能会让事情更清楚一些:

 switch (indexPath.row % 4) {
 case 0:
      [cell setColor:[UIColor colorFromHexString:@"35a8e1"]];
      break;
 case 1:
      [cell setColor:[UIColor colorFromHexString:@"5cb14c"]];
      break;
 case 2:
      [cell setColor:[UIColor colorFromHexString:@"ec292d"]];
      break;
 case 3:
      [cell setColor:[UIColor colorFromHexString:@"ee8c1d"]];
      break;
}

UIColor
中没有
colorFromHexString:
类方法。您是否创建了UIColor的类别?如果你有,请发布你的代码。是的,我有,它也来自SA…在
UIColor
中没有
colorFromHexString:
类方法。您是否创建了UIColor的类别?如果你有,请发布你的代码。是的,我有,它也来自SA…在
UIColor
中没有
colorFromHexString:
类方法。您是否创建了UIColor的类别?如果你有,请发布你的代码。是的,我有,它也来自SA…在
UIColor
中没有
colorFromHexString:
类方法。您是否创建了UIColor的类别?如果你有,请发布你的代码。是的,我有,这也是来自SA…哎呀,看起来你比我快了几秒钟!长if/else链阅读起来很糟糕,为什么不切换(indexPath.row%4){case 0://etc.}//edit我在下面的答案中没有看到这个,抱歉,继续:)哎呀,看起来你比我快了几秒钟!长if/else链阅读起来很糟糕,为什么不切换(indexPath.row%4){case 0://etc.}//edit我在下面的答案中没有看到这个,抱歉,继续:)哎呀,看起来你比我快了几秒钟!长if/else链阅读起来很糟糕,为什么不切换(indexPath.row%4){case 0://etc.}//edit我在下面的答案中没有看到这个,抱歉,继续:)哎呀,看起来你比我快了几秒钟!长if/else链读起来很糟糕,为什么不切换(indexPath.row%4){case 0://etc.}//edit我在下面的答案中没有看到这个,抱歉,继续:)