在iPhone 5c发布后,我很好奇是否有人知道如何获得iPhone 5c colored颜色 的API?我相信每个人都会发现将相应的UI colored颜色 方案加载到设备 colored颜色 中很方便.

我正在考虑将其包装成UIDevice类别,它将返回UIColor.

Update:

Please note, that in case of iPhone 5c, what you are really looking for is deviceEnclosureColor, as deviceColor will always return #3b3b3c, as it is a front colour.

方法签名:

-(id)_deviceInfoForKey:(struct __CFString { }*)arg1

UIIT设备类别:

@interface UIDevice (deviceColour)

- (id)_deviceInfoForKey:(struct __CFString { }*)arg1;
- (NSString*)deviceColourString_UntilAppleMakesItPublic;
- (NSString*)deviceEnclosureColour_UntilAppleMakesItPublic;


@end

@implementation UIDevice (deviceColour)

- (NSString*)deviceColourString_UntilAppleMakesItPublic
{
    return [self _deviceInfoForKey:@"DeviceColor"];
}

- (NSString*)deviceEnclosureColour_UntilAppleMakesItPublic
{
    return [self _deviceInfoForKey:@"DeviceEnclosureColor"];
}


@end

推荐答案

有一个私有API来检索DeviceColorDeviceEnclosureColor.对于iPhone 5c,有趣的部分是shell colored颜色 (设备 colored颜色 =正面 colored颜色 总是#3b3c).

UIDevice *device = [UIDevice currentDevice];
SEL selector = NSSelectorFromString(@"deviceInfoForKey:");
if (![device respondsToSelector:selector]) {
    selector = NSSelectorFromString(@"_deviceInfoForKey:");
}
if ([device respondsToSelector:selector]) {
    NSLog(@"DeviceColor: %@ DeviceEnclosureColor: %@", [device performSelector:selector withObject:@"DeviceColor"], [device performSelector:selector withObject:@"DeviceEnclosureColor"]);
}

我在博客上写过这一点,并提供了一个示例应用程序:

http://www.futuretap.com/blog/device-colors/

Warning: As mentioned, this is a private API. Don't use this in App Store builds.

Objective-c相关问答推荐

通过指针算术访问数组值与 C 中的下标

iphone - 防止uiscrollview通过滚动

如何将 CGPoint 添加到 NSMutableArray?

将 HEX NSString 转换为 NSData

iPhone:推送通知后如何删除徽章?

在 Objective-C 中在 iPhone 上使用 HTTP POST 和 GET 的教程

CABasicAnimation 无 HUGE_VALF 无限重复?

如何判断 Cocoa 和 Objective-C 中是否存在文件夹?

如何在另一个视图中获取视图的框架?

dispatch_get_global_queue vs dispatch_get_main_queue

distanceFromLocation - 计算两点之间的距离

使用 OpenCV 在 iOS 中进行透视变换 + 裁剪

Objective-C:前向类声明

UIWebView didFinishLoading 多次触发

如何在 Cocoa 中获取 NSArray 的第一个 x 元素?

自定义导航栏样式 - iOS

`[super viewDidLoad]` 约定

所有异常断点在模拟器上无缘无故停止

状态栏文本 colored颜色 iOS 7

info.plist 中的Application Requires iPhone Environment键是什么意思?