【问题标题】:OS color difference between interface builder and screenshot (simulator & device)界面生成器和屏幕截图(模拟器和设备)之间的操作系统颜色差异
【发布时间】:2015-05-29 02:34:31
【问题描述】:

如果我在界面生成器中设置 rootview 的背景颜色,我会得到错误的背景颜色(与原始值不同)。如果我以编程方式设置它,则视图具有正确的背景颜色。 有什么我没看到的吗?

我使用 XIB,没有故事板...

编辑(对场景和问题的更详细描述):

我在 interfacebuilder 中定义了我的页面(视图)并设置了 RGB(100、100、100)的背景颜色。

在我的 AppDelegate 中,我有以下代码:

UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;

IndexViewController *indexViewController = [[IndexViewController alloc] init];

self.viewController = indexViewController;
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;

如果我随后截取应用程序的屏幕截图,我会得到 RGB(81、81、81)的背景颜色。

IndexViewController 什么都不做。在 viewDidLoad 方法中设置视图控制器的根视图的背景颜色时,结果颜色是正确的。

[self.view setBackgroundColor:[UIColor colorWithHex:@"#646464" alpha:1.0]];

我尝试自己解决了几个小时的问题,但我在 ios 开发方面没有那么丰富的经验。希望有人能帮忙!

解决方案:

  1. 转到系统首选项 -> 显示 -> 颜色并选择 “通用 RGB”
  2. 在界面构建器的颜色选择器中单击 下拉菜单(RGB 滑块)旁边的齿轮并选择“通用 RGB”

注意!如果您输入 rgb 值,请不要将焦点放在“Hex Color #”输入上。一旦发生这种情况,颜色选择器会将颜色配置文件重置为“sRGB ...”。这似乎是一个错误!?

【问题讨论】:

  • 您能告诉我们您在 XIB 中以编程方式使用的颜色吗?
  • 很明显,有些东西我们看不到.....您提供的任何示例,我们可以用来帮助您解决看起来更像您没有花费的问题的任何东西在这个问题上花了很多时间来真正自己解决它
  • 点击下拉菜单旁边的轮子并选择通用 rgb。
  • 谢谢菲利普。与此同时,我发现了同样的灵魂。
  • @Dan 加油,本站不是论坛,有特定格式!标题中没有“解决”。这是问题和答案。

标签: ios xib background-color


【解决方案1】:

看起来像你的功能: [UIColor colorWithHex:@"#646464" alpha:1.0] 正在创造这种差异。

试试这个:

- (UIColor *)colorFromRGBHexString:(NSString *)colorString {
if(colorString.length == 7) {
    const char *colorUTF8String = [colorString UTF8String];
    int r, g, b;
    sscanf(colorUTF8String, "#%2x%2x%2x", &r, &g, &b);
    return [UIColor colorWithRed:(r / 255.0) green:(g / 255.0) blue:(b / 255.0) alpha:1.0];
}    
return nil;
}

【讨论】:

  • 不,这不是问题,因为如果我用这种方法设置颜色,我会得到正确的结果。请看我上面的解决方案。
  • 您使用哪个设备拍摄快照?还是使用模拟器?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-03-04
  • 1970-01-01
  • 2023-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多