-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppUtils.m
executable file
·282 lines (215 loc) · 7.08 KB
/
AppUtils.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
//
// AppUtils.m
// GreenTravel
//
// Created by Jeffwang on 14/10/31.
// Copyright (c) 2014年 Ugoodtech. All rights reserved.
//
#import "AppUtils.h"
#import "AppMacro.h"
#import "sys/utsname.h"
@implementation AppUtils
/*
+(UIImage *)buttonHighlightedColor:(CGSize )size
{
CGSize imageSize = CGSizeMake(size.width, size.height);
UIGraphicsBeginImageContextWithOptions(imageSize, 0, [UIScreen mainScreen].scale);
[[UIColor colorWithCGColor:[UIColor blackColor].CGColor] setFill];//RGB(179,233,246)
UIRectFill(CGRectMake(0, 0, imageSize.width, imageSize.height));
UIImage *pressedColorImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return pressedColorImg;
}
*/
+(float) getSystemVersion {
return [[[UIDevice currentDevice] systemVersion] floatValue];
}
+ (NSString*) deviceString //判断设备类型
{
// 需要#import "sys/utsname.h"
struct utsname systemInfo;
uname(&systemInfo);
NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
/*if ([platform isEqualToString:@"iPhone5,1"]) return @"iPhone 5";
if ([platform isEqualToString:@"iPhone5,2"]) return @"iPhone 5 (GSM+CDMA)";
*/
return platform;
}
+(CGFloat)is6plus
{
if ([[self deviceString]isEqualToString:@"iPhone 6 Plus"])
return 86;
else
return 64;
}
+(BOOL)isBlankString:(NSString *)string
{
if (string == nil || string == NULL) {
return YES;
}
if ([string isKindOfClass:[NSNull class]]) {
return YES;
}
if ([string isEqualToString:@""]||[string isEqualToString:@"(null)"]) {
return YES;
}
if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {
return YES;
}
return NO;
}
+(NSString *)metreConvertKM:(int)distanceMetre
{
int KMDouble=distanceMetre/1000;
NSString *kmString=[NSString stringWithFormat:@"%d公里",KMDouble];
return kmString;
}
/**
*
*
* @param navigationController
*
* @return
*/
/*
+(UIBarButtonItem *) getLeftSelfNavtionControllerItem:(JWNavigationController*)navigationController
{
UIButton *backButton=[UIButton buttonWithType:UIButtonTypeCustom];
[backButton setFrame:CGRectMake(0, 0, 51, 44)];
[backButton setShowsTouchWhenHighlighted:YES];
[backButton setTag:1000];
[backButton setImage:[UIImage imageNamed:@"btn_back_normal"] forState:UIControlStateNormal];
[backButton setImage:[UIImage imageNamed:@"btn_back_pressed"] forState:UIControlStateHighlighted];
[backButton setImageEdgeInsets: UIEdgeInsetsMake(0, -30, 0, 0)];
// [backButton setAction:kUIButtonBlockTouchUpInside withBlock:^{
[navigationController popViewControllerAnimated:YES];
}];
UIBarButtonItem *barleftItem=[[UIBarButtonItem alloc] initWithCustomView:backButton];
return barleftItem;
}
*/
+(NSString*)getDateTimeNowToString
{
NSDate *currentDate=[NSDate date];
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSString * locationString=[dateFormatter stringFromDate:currentDate];
return locationString;
}
+(NSString *) DataTOjsonString:(id)object
{
NSString *jsonString = nil;
NSError *error;
NSData *jsonData=[NSJSONSerialization dataWithJSONObject:object options:NSJSONWritingPrettyPrinted error:&error];
if (!jsonData) {
NSLog(@"Got an error: %@", error);
}
else{
jsonString=[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
return jsonString;
}
+(NSString *)getDateTimeTheOneOfWorld
{
NSDate *currentDate=[NSDate date];
NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[currentDate timeIntervalSince1970]];
return timeSp;
}
+(NSString *) kServierUrlString:(NSString *)addressUrl
{
NSString *url=[NSString stringWithFormat:@"%@%@",kServerIp,addressUrl];
return url;
}
+(NSString *) getAppCurrentVersion
{
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
return app_Version;
}
+(NSString *)getAppCurrentOSType
{
UIDevice *devide=[[UIDevice alloc] init];
NSString *currentOSType=devide.systemName;
//[NSString stringWithFormat:@"%@%@",devide.systemName,devide.systemVersion];
return currentOSType;
}
+(NSString*)getAppCurrentOSVersion
{
UIDevice *devide=[[UIDevice alloc] init];
return devide.systemVersion;
}
+(NSString *) getAppCurrentUserId
{
return [[NSUserDefaults standardUserDefaults] objectForKey:@"tempUserId"];
}
+(BOOL)requestIsTrue:(NSString *)status
{
__block BOOL haveResult=NO;
if ([status isEqualToString:@"success"]) {
haveResult=YES;
}
return haveResult;
}
+(UILabel *)setTitleLabel:(NSString *)titleName
{
UILabel *titleLB = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 70, 35)];
titleLB.adjustsFontSizeToFitWidth = YES;
titleLB.font = [UIFont fontWithName:font_zhong size:19.0];//Arial-BoldItalicMT
// titleLB.font = [UIFont boldSystemFontOfSize: 19];
titleLB.textAlignment = NSTextAlignmentCenter;
titleLB.textColor = customedBlue;
titleLB.text = titleName;
return titleLB;
}
+(UIView *)setTitleView:(NSString *)titleName
{
UILabel *titleLB = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 30)];
titleLB.adjustsFontSizeToFitWidth = YES;
titleLB.font = [UIFont fontWithName:font_zhong size:19.0];//Arial-BoldItalicMT
// titleLB.font = [UIFont boldSystemFontOfSize: 19];
titleLB.layer.masksToBounds = YES;
titleLB.textAlignment = NSTextAlignmentCenter;
titleLB.textColor = [UIColor whiteColor];
titleLB.backgroundColor = customedBlue;
titleLB.text = titleName;
[titleLB.layer setCornerRadius:5.0];
titleLB.layer.borderWidth = 1;
titleLB.layer.borderColor = customedBlue.CGColor;
return titleLB;
}
/*
+(void)showLoading:(NSString *)lodingStatus
{
NSString *status=lodingStatus;
if ([AppUtils isBlankString:lodingStatus]) {
status=@"加载中···";
}
[KVNProgress showWithStatus:status];
}
+(void)hideLoaing
{
[KVNProgress dismiss];
}
*/
+(NSString *)checkTel:(NSString *)str
{
if ([str length] == 0) {
return @"电话号码不能为空";
}
NSString *regex = @"^((1[3|7][0-9])|(147)|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";//|(17[0-9])
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
BOOL isMatch = [pred evaluateWithObject:str];
if (!isMatch) {
return @"电话号不正确";
}
return @"";
}
+ (UIImage *)pixelImageWithColor:(UIColor *)color {
UIGraphicsBeginImageContextWithOptions((CGSize){1.0f, 1.0f}, YES, 0.0f);
[color setFill];
[[UIBezierPath bezierPathWithRect:(CGRect){CGPointZero, {1.0f, 1.0f}}] fill];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return [img resizableImageWithCapInsets:UIEdgeInsetsZero];
}
@end