ios - CGGradient 在 iPad 1 和 2 上显示不正确

标签 ios ipad gradient quartz-graphics

我一直在尝试为我的 iOS 应用程序的 UI 创建我自己的渐变。我首先使用了 CAGradientLayer,但我对“阶梯式”外观感到失望,所以我一直在尝试 CGGradient。

   - (void)drawRect:(CGRect)rect
    {

        CGContextRef currentContext = UIGraphicsGetCurrentContext();

        CGGradientRef skyGradient;
        CGColorSpaceRef rgbColorspace;
        size_t num_locations = 3;
        CGFloat locations[3] = { 0.0, .5, 1.0 };
        CGFloat components[12] = { .106, .73,  .93333, 1.,
                                  0.0,  0.0 , 1.0,     1., 
                                   .106, .73,  .93333, 1. };

        rgbColorspace = CGColorSpaceCreateDeviceRGB();
        skyGradient = CGGradientCreateWithColorComponents(rgbColorspace, components, locations, num_locations);

        CGRect currentBounds = self.bounds;
        CGPoint topLeft = CGPointMake(0.0f, 0.0f);
        CGPoint bottomRight = CGPointMake(CGRectGetMaxX(currentBounds), CGRectGetMaxY(currentBounds));
        CGContextDrawLinearGradient(currentContext, skyGradient, topLeft, bottomRight, 0);

        CGGradientRelease(skyGradient);
        CGColorSpaceRelease(rgbColorspace); 

    }

我在正确显示渐变方面遇到问题。我有三台 iPad——每一代一台。渐变在 iPad 3 上看起来正确,但在 iPad 1 或 2 上却不正确。这真的很奇怪。我打算截屏并发布两个差异,但更奇怪的是,屏幕截图看起来一样(是的,两者的亮度相同)。

旧 iPad 上的颜色似乎真的褪色了。我知道 iPad 3 是视网膜显示屏,但我认为它一定不止于此。

Not a great picture, but you can still see a drastic difference.

最佳答案

正如 David Rönnqvist 所指出的,这个问题的答案是这些设备根本不会以相同的方式显示颜色。对此没有简单的解决方案,也许解决方案会过度杀戮。

关于ios - CGGradient 在 iPad 1 和 2 上显示不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10988279/

相关文章:

ios - 具有重复条目的地址簿

ios - RestKit:如何批处理多个请求并在完成后获得响应?

ios - 配置文件未显示在管理器中

ios - 并排显示tableviewcell

android - Java中的渐变背景颜色

ios - 在 Xcode 的 UIWebView 中更改内容背景颜色

ipad - 直接链接到iPad上的App Store?

ios - UITabBarController 中的 View 具有 16 像素缓冲区

css - 如何仅使用 CSS 制作背景模糊渐变?

css - 如何应用背景渐变样式css