Skip to content

Commit 7af7565

Browse files
committed
3.0.4
1 parent 09870d5 commit 7af7565

File tree

6 files changed

+198
-1
lines changed

6 files changed

+198
-1
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// UIDevice+YAInfo.h
3+
// YAUIKit
4+
//
5+
// Created by candyan on 12/18/15.
6+
// Copyright © 2015 YAUIKit. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface UIDevice (YAInfo)
12+
13+
- (NSString *)ya_modelName;
14+
15+
@end
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
//
2+
// UIDevice+YAInfo.m
3+
// YAUIKit
4+
//
5+
// Created by candyan on 12/18/15.
6+
// Copyright © 2015 YAUIKit. All rights reserved.
7+
//
8+
9+
#import "UIDevice+YAInfo.h"
10+
#import <sys/utsname.h>
11+
12+
@implementation UIDevice (YAInfo)
13+
14+
- (NSString *)ya_modelName
15+
{
16+
struct utsname systemInfo;
17+
18+
uname(&systemInfo);
19+
20+
NSString *code = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
21+
22+
static NSDictionary *deviceNamesByCode = nil;
23+
24+
if (!deviceNamesByCode) {
25+
26+
deviceNamesByCode = @{
27+
@"i386" : @"Simulator",
28+
@"x86_64" : @"Simulator",
29+
@"iPod1,1" : @"iPod Touch", // (Original)
30+
@"iPod2,1" : @"iPod Touch 2", // (Second Generation)
31+
@"iPod3,1" : @"iPod Touch 3", // (Third Generation)
32+
@"iPod4,1" : @"iPod Touch 4", // (Fourth Generation)
33+
@"iPod5,1" : @"iPod Touch 5", // (Fifth Generation)
34+
@"iPod6,1" : @"iPod Touch 6", // (Sixth Generation)
35+
@"iPad1,1" : @"iPad", // (Original)
36+
@"iPad1,2" : @"iPad", // (Original 3G)
37+
@"iPad2,1" : @"iPad 2", // (2nd Generation)
38+
@"iPad2,2" : @"iPad 2", // (2nd Generation)
39+
@"iPad2,3" : @"iPad 2", // (2nd Generation)
40+
@"iPad2,4" : @"iPad 2", // (2nd Generation)
41+
@"iPad2,5" : @"iPad Mini", // (Original)
42+
@"iPad2,6" : @"iPad Mini", // (Original)
43+
@"iPad2,7" : @"iPad Mini", // (Original)
44+
@"iPad3,1" : @"iPad 3", // (3rd Generation)
45+
@"iPad3,2" : @"iPad 3", // (3rd Generation)
46+
@"iPad3,3" : @"iPad 3", // (3rd Generation)
47+
@"iPad3,4" : @"iPad 4", // (4th Generation)
48+
@"iPad3,5" : @"iPad 4", // (4th Generation)
49+
@"iPad3,6" : @"iPad 4", // (4th Generation)
50+
@"iPad4,1" : @"iPad Air", // 5th Generation iPad (iPad Air) - Wifi
51+
@"iPad4,2" : @"iPad Air", // 5th Generation iPad (iPad Air) - Cellular GSM
52+
@"iPad4,3" : @"iPad Air", // 5th Generation iPad (iPad Air) - Cellular CDMA
53+
@"iPad4,4" : @"iPad Mini 2", // (2nd Generation iPad Mini - Wifi)
54+
@"iPad4,5" : @"iPad Mini 2", // (2nd Generation iPad Mini - Cellular CDMA)
55+
@"iPad4,6" : @"iPad Mini 2", // (2nd Generation iPad Mini - Cellular CN)
56+
@"iPad4,7" : @"iPad Mini 3", // (3rd Generation iPad Mini - Cellular CN)
57+
@"iPad4,8" : @"iPad Mini 3", // (3rd Generation iPad Mini - Cellular CN)
58+
@"iPad5,3" : @"iPad Air 2", // (2nd Generation iPad Air - Cellular CN)
59+
@"iPad5,4" : @"iPad Air 2", // (2nd Generation iPad Air - Cellular CN)
60+
@"iPad6,8" : @"iPad Pro",
61+
@"iPhone1,1" : @"iPhone", // (Original)
62+
@"iPhone1,2" : @"iPhone 3G", // (3G)
63+
@"iPhone2,1" : @"iPhone 3GS", // (3GS)
64+
@"iPhone3,1" : @"iPhone 4", // (GSM)
65+
@"iPhone3,2" : @"iPhone 4", // (GSM)
66+
@"iPhone3,3" : @"iPhone 4", // (CDMA/Verizon/Sprint)
67+
@"iPhone4,1" : @"iPhone 4S", //
68+
@"iPhone5,1" : @"iPhone 5", // (model A1428, AT&T/Canada)
69+
@"iPhone5,2" : @"iPhone 5", // (model A1429, everything else)
70+
@"iPhone5,3" : @"iPhone 5c", // (model A1456, A1532 | GSM)
71+
@"iPhone5,4" : @"iPhone 5c", // (model A1507, A1516, A1526 (China), A1529 | Global)
72+
@"iPhone6,1" : @"iPhone 5s", // (model A1433, A1533 | GSM)
73+
@"iPhone6,2" : @"iPhone 5s", // (model A1457, A1518, A1528 (China), A1530 | Global)
74+
@"iPhone7,1" : @"iPhone 6 Plus", //
75+
@"iPhone7,2" : @"iPhone 6", //
76+
@"iPhone8,1" : @"iPhone 6s", //
77+
@"iPhone8,2" : @"iPhone 6s Plus", //
78+
@"AppleTV2,1" : @"Apple TV 2G", //
79+
@"AppleTV3,1" : @"Apple TV 3", //
80+
@"AppleTV3,2" : @"Apple TV 3 (2013)", //
81+
};
82+
}
83+
84+
NSString *deviceName = [deviceNamesByCode objectForKey:code];
85+
86+
if (!deviceName) {
87+
// Not found on database. At least guess main device type from string contents:
88+
89+
if ([code rangeOfString:@"iPod"].location != NSNotFound) {
90+
deviceName = @"iPod Touch";
91+
}
92+
else if ([code rangeOfString:@"iPad"].location != NSNotFound) {
93+
deviceName = @"iPad";
94+
}
95+
else if ([code rangeOfString:@"iPhone"].location != NSNotFound) {
96+
deviceName = @"iPhone";
97+
}
98+
}
99+
100+
return deviceName;
101+
}
102+
103+
@end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// UIImage+YAScreenImage.h
3+
// YAUIKit
4+
//
5+
// Created by liuyan on 12/18/15.
6+
// Copyright © 2015 liu yan. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface UIImage (YAScreenImage)
12+
13+
+ (UIImage *)screenImageWithName:(NSString *)imageName;
14+
15+
@end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// UIImage+YAScreenImage.m
3+
// YAUIKit
4+
//
5+
// Created by liuyan on 12/18/15.
6+
// Copyright © 2015 liu yan. All rights reserved.
7+
//
8+
9+
#import "UIImage+YAScreenImage.h"
10+
11+
@implementation UIImage (YAScreenImage)
12+
13+
+ (UIImage *)screenImageWithName:(NSString *)imageName
14+
{
15+
CGFloat screenHeight = CGRectGetHeight([UIScreen mainScreen].bounds);
16+
CGFloat screenScale = [UIScreen mainScreen].scale;
17+
18+
NSString *imageFullName = nil;
19+
if (screenHeight == 480) {
20+
if (screenScale > 1) {
21+
imageFullName = [NSString stringWithFormat:@"%@_480h@2x", imageName];
22+
}
23+
else {
24+
imageFullName = [NSString stringWithFormat:@"%@_480h", imageName];
25+
}
26+
}
27+
else if (screenHeight == 568) {
28+
imageFullName = [NSString stringWithFormat:@"%@_568h@2x", imageName];
29+
}
30+
else if (screenHeight == 667) {
31+
imageFullName = [NSString stringWithFormat:@"%@_667h@2x", imageName];
32+
}
33+
else if (screenHeight == 736) {
34+
imageFullName = [NSString stringWithFormat:@"%@_736h@3x", imageName];
35+
}
36+
else {
37+
return [UIImage imageNamed:imageName];
38+
}
39+
40+
NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageFullName ofType:@"png"];
41+
return [[UIImage alloc] initWithContentsOfFile:imagePath];
42+
}
43+
44+
@end

YAUIKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = 'YAUIKit'
4-
s.version = '3.0.3'
4+
s.version = '3.0.4'
55
s.summary = 'YAUIKit'
66
s.homepage = 'https://github.com/candyan/YAUIKit'
77
s.license = 'MIT'

YAUIKit/YAUIKit.xcodeproj/project.pbxproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
7571AB3D1C23E8CA008DCBA4 /* UIGestureRecognizer+YABlockAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 7571AB3C1C23E8CA008DCBA4 /* UIGestureRecognizer+YABlockAction.m */; };
7171
7571AB411C23EA40008DCBA4 /* UIScrollView+YAScroll.m in Sources */ = {isa = PBXBuildFile; fileRef = 7571AB401C23EA40008DCBA4 /* UIScrollView+YAScroll.m */; };
7272
7571AB451C23F07D008DCBA4 /* UIWindow+YAHierarchy.m in Sources */ = {isa = PBXBuildFile; fileRef = 7571AB441C23F07D008DCBA4 /* UIWindow+YAHierarchy.m */; };
73+
7571AB491C23FA47008DCBA4 /* UIDevice+YAInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 7571AB481C23FA47008DCBA4 /* UIDevice+YAInfo.m */; };
74+
7571AB4C1C23FBFE008DCBA4 /* UIImage+YAScreenImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 7571AB4B1C23FBFE008DCBA4 /* UIImage+YAScreenImage.m */; };
7375
75900D2F19E4438E00C05D28 /* UIBarButtonItem+YAItemFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 75900CF119E4438E00C05D28 /* UIBarButtonItem+YAItemFactory.m */; };
7476
75900D3019E4438E00C05D28 /* UIColor+YAHexColor.m in Sources */ = {isa = PBXBuildFile; fileRef = 75900CF419E4438E00C05D28 /* UIColor+YAHexColor.m */; };
7577
75900D3119E4438E00C05D28 /* UIControl+YAUIKit.m in Sources */ = {isa = PBXBuildFile; fileRef = 75900CF719E4438E00C05D28 /* UIControl+YAUIKit.m */; };
@@ -181,6 +183,10 @@
181183
7571AB401C23EA40008DCBA4 /* UIScrollView+YAScroll.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIScrollView+YAScroll.m"; sourceTree = "<group>"; };
182184
7571AB431C23F07D008DCBA4 /* UIWindow+YAHierarchy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIWindow+YAHierarchy.h"; sourceTree = "<group>"; };
183185
7571AB441C23F07D008DCBA4 /* UIWindow+YAHierarchy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIWindow+YAHierarchy.m"; sourceTree = "<group>"; };
186+
7571AB471C23FA47008DCBA4 /* UIDevice+YAInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice+YAInfo.h"; sourceTree = "<group>"; };
187+
7571AB481C23FA47008DCBA4 /* UIDevice+YAInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice+YAInfo.m"; sourceTree = "<group>"; };
188+
7571AB4A1C23FBFE008DCBA4 /* UIImage+YAScreenImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+YAScreenImage.h"; sourceTree = "<group>"; };
189+
7571AB4B1C23FBFE008DCBA4 /* UIImage+YAScreenImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+YAScreenImage.m"; sourceTree = "<group>"; };
184190
75900CF019E4438E00C05D28 /* UIBarButtonItem+YAItemFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIBarButtonItem+YAItemFactory.h"; sourceTree = "<group>"; };
185191
75900CF119E4438E00C05D28 /* UIBarButtonItem+YAItemFactory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIBarButtonItem+YAItemFactory.m"; sourceTree = "<group>"; };
186192
75900CF319E4438E00C05D28 /* UIColor+YAHexColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIColor+YAHexColor.h"; sourceTree = "<group>"; };
@@ -490,6 +496,15 @@
490496
path = UIWindow;
491497
sourceTree = "<group>";
492498
};
499+
7571AB461C23FA23008DCBA4 /* UIDevice */ = {
500+
isa = PBXGroup;
501+
children = (
502+
7571AB471C23FA47008DCBA4 /* UIDevice+YAInfo.h */,
503+
7571AB481C23FA47008DCBA4 /* UIDevice+YAInfo.m */,
504+
);
505+
path = UIDevice;
506+
sourceTree = "<group>";
507+
};
493508
75900CED19E4438E00C05D28 /* Source */ = {
494509
isa = PBXGroup;
495510
children = (
@@ -517,6 +532,7 @@
517532
75900CEE19E4438E00C05D28 /* Extend */ = {
518533
isa = PBXGroup;
519534
children = (
535+
7571AB461C23FA23008DCBA4 /* UIDevice */,
520536
7571AB421C23F046008DCBA4 /* UIWindow */,
521537
7571AB3E1C23EA33008DCBA4 /* UIScrollView */,
522538
7571AB3A1C23E8BA008DCBA4 /* UIGestureRecognizer */,
@@ -580,6 +596,8 @@
580596
75900CFF19E4438E00C05D28 /* UIImage+YAImageTransform.m */,
581597
75900D0019E4438E00C05D28 /* UIImage+YAUIKit.h */,
582598
75900D0119E4438E00C05D28 /* UIImage+YAUIKit.m */,
599+
7571AB4A1C23FBFE008DCBA4 /* UIImage+YAScreenImage.h */,
600+
7571AB4B1C23FBFE008DCBA4 /* UIImage+YAScreenImage.m */,
583601
);
584602
path = UIImage;
585603
sourceTree = "<group>";
@@ -858,8 +876,10 @@
858876
75900D4119E4438E00C05D28 /* YAPlaceHolderTextView.m in Sources */,
859877
753BBA081A3AA18A00D4A50E /* YAInfiniteScroll.m in Sources */,
860878
75900D3019E4438E00C05D28 /* UIColor+YAHexColor.m in Sources */,
879+
7571AB491C23FA47008DCBA4 /* UIDevice+YAInfo.m in Sources */,
861880
75900D4019E4438E00C05D28 /* YAPanController.m in Sources */,
862881
7557F79B19E9A75800153B2E /* YATableViewController.m in Sources */,
882+
7571AB4C1C23FBFE008DCBA4 /* UIImage+YAScreenImage.m in Sources */,
863883
7571AB411C23EA40008DCBA4 /* UIScrollView+YAScroll.m in Sources */,
864884
75900D3519E4438E00C05D28 /* UIImage+YAUIKit.m in Sources */,
865885
75900D4219E4438E00C05D28 /* YARefreshControl.m in Sources */,

0 commit comments

Comments
 (0)