BaseViewController.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. //
  2. // BaseViewController.m
  3. // IBOSS
  4. //
  5. // Created by iHope on 14-7-7.
  6. // Copyright (c) 2017年 沈阳东科云信软件有限公司. All rights reserved.
  7. //
  8. // 功能描述:控制器基础类
  9. //
  10. #import "BaseViewController.h"
  11. #include <ifaddrs.h>
  12. #include <arpa/inet.h>
  13. @interface BaseViewController ()<UIAlertViewDelegate>{
  14. // 进度条
  15. MBProgressHUD *_mLoadView;
  16. // 进度条
  17. NewMBProgressHUD *_mNewLoadView;
  18. // logo
  19. UIImageView *_mLogoView;
  20. }
  21. @end
  22. @implementation BaseViewController
  23. /**
  24. 进度条
  25. */
  26. @synthesize hud;
  27. /**
  28. 标题
  29. */
  30. @synthesize mlbTitle;
  31. /**
  32. 代理
  33. */
  34. @synthesize delegate;
  35. /**
  36. 返回sel
  37. */
  38. @synthesize onGoBack;
  39. /**
  40. 顶部颜色
  41. */
  42. @synthesize mTopColor;
  43. /**
  44. 顶部图片
  45. */
  46. @synthesize mTopImage;
  47. /**
  48. 加载消息
  49. */
  50. @synthesize mLoadMsg;
  51. /**
  52. 标题颜色
  53. */
  54. @synthesize mTitleColor;
  55. /**
  56. 右导航标示
  57. */
  58. @synthesize mbLightNav;
  59. /**
  60. viewDidLoad
  61. */
  62. - (void)viewDidLoad
  63. {
  64. [super viewDidLoad];
  65. hud = [[MBProgressHUD alloc] initWithView:self.view] ;
  66. [self.view addSubview:hud];
  67. // [self.view bringSubviewToFront:hud];
  68. self.view.backgroundColor = [UIColor colorWithWhite:0.96 alpha:1.0];
  69. if (IOS_7) {
  70. //去掉边缘化 适配
  71. self.edgesForExtendedLayout = UIRectEdgeNone;
  72. self.extendedLayoutIncludesOpaqueBars = NO;
  73. self.automaticallyAdjustsScrollViewInsets = NO;
  74. if (!mbLightNav) {
  75. self.navigationController.navigationBar.translucent = NO;
  76. }
  77. }
  78. [self refreshNavColor];
  79. [self addLeftImageBtn:nil target:nil action:nil];
  80. [self addRightImageBtn:nil target:nil action:nil];
  81. }
  82. /**
  83. viewWillAppear
  84. @param animated <#animated description#>
  85. */
  86. - (void)viewWillAppear:(BOOL)animated {
  87. [super viewWillAppear:animated];
  88. // [SelectTabBar Share].hidden = YES;
  89. }
  90. /**
  91. didReceiveMemoryWarning
  92. */
  93. - (void)didReceiveMemoryWarning
  94. {
  95. [super didReceiveMemoryWarning];
  96. // Dispose of any resources that can be recreated.
  97. }
  98. /**
  99. dealloc
  100. */
  101. - (void)dealloc {
  102. self.mTopColor = nil;
  103. self.mTopImage = nil;
  104. self.mLoadMsg = nil;
  105. }
  106. /**
  107. 初始化
  108. @param nibNameOrNil <#nibNameOrNil description#>
  109. @param nibBundleOrNil <#nibBundleOrNil description#>
  110. @return <#return value description#>
  111. */
  112. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  113. {
  114. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  115. if (self) {
  116. mbLightNav = YES;
  117. self.mTopImage = [UIImage imageNamed:IOS_7?@"bk_cs@2x.png":@"bk_cs.png"];
  118. }
  119. return self;
  120. }
  121. /**
  122. 将数据转换成字符串
  123. @param arr <#arr description#>
  124. @return <#return value description#>
  125. */
  126. - (NSString *)getArrToString:(NSArray *)arr
  127. {
  128. if(!arr) return nil;
  129. NSMutableString *totalstr = [[NSMutableString alloc] init];
  130. for(int i=0;i<arr.count;i++)
  131. {
  132. NSString *tempStr=arr[i];
  133. [totalstr appendFormat:@"%@%@",tempStr,@"," ];
  134. }
  135. return [totalstr substringToIndex:totalstr.length-1];
  136. }
  137. /**
  138. ip地址
  139. @return <#return value description#>
  140. */
  141. - (NSString *)IPAddress
  142. {
  143. NSString *address = @"error";
  144. struct ifaddrs *interfaces = NULL;
  145. struct ifaddrs *temp_addr = NULL;
  146. int success = 0;
  147. // retrieve the current interfaces - returns 0 on success
  148. success = getifaddrs(&interfaces);
  149. if (success == 0) {
  150. // Loop through linked list of interfaces
  151. temp_addr = interfaces;
  152. while (temp_addr != NULL) {
  153. if( temp_addr->ifa_addr->sa_family == AF_INET) {
  154. // Check if interface is en0 which is the wifi connection on the iPhone
  155. if ([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) {
  156. // Get NSString from C String
  157. address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
  158. }
  159. }
  160. temp_addr = temp_addr->ifa_next;
  161. }
  162. }
  163. // Free memory
  164. freeifaddrs(interfaces);
  165. return address;
  166. }
  167. /**
  168. 设备信息
  169. */
  170. - (void)getDeviceAndOSInfo
  171. {
  172. //here use sys/utsname.h
  173. struct utsname systemInfo;
  174. uname(&systemInfo);
  175. //get the device model and the system version
  176. NSLog(@"%@", [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding]);
  177. }
  178. /**
  179. 标题
  180. @param text <#text description#>
  181. */
  182. - (void)showTitle:(NSString*)text{
  183. self.navigationItem.title = text;
  184. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  185. [button setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
  186. [button addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
  187. button.frame = CGRectMake(0, 0,45,22);
  188. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
  189. }
  190. /**
  191. 标题
  192. @param text <#text description#>
  193. @param nav <#nav description#>
  194. */
  195. - (void)showTitle:(NSString*)text navi:(UINavigationController*)nav{
  196. nav.navigationItem.title = text;
  197. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  198. [button setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
  199. [button addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
  200. button.frame = CGRectMake(0, 0,45,22);
  201. nav.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
  202. }
  203. /**
  204. 文本加载中
  205. @param text <#text description#>
  206. */
  207. - (void)showLoadingText:(NSString*)text
  208. {
  209. // self.hud = nil;
  210. // [hud release];
  211. //如果设置此属性则当前的view置于后台
  212. hud.dimBackground = YES;
  213. //设置对话框文字
  214. hud.labelText = text;
  215. [hud show:YES];
  216. }
  217. /**
  218. 进度条加载中。。。。
  219. */
  220. - (void)showLoading
  221. {
  222. hud.dimBackground = YES;
  223. hud.labelText = @"正在加载";
  224. [hud show:YES];
  225. }
  226. /**
  227. 进度条隐藏
  228. */
  229. - (void) hideLoading
  230. {
  231. [hud hide:YES];
  232. }
  233. /**
  234. 显示消息
  235. @param text <#text description#>
  236. */
  237. - (void)showAlertViewText:(NSString *)text
  238. {
  239. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:text preferredStyle:UIAlertControllerStyleAlert ];
  240. [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
  241. }]];
  242. // 3.显示alertController:presentViewController
  243. [self presentViewController:alert animated:YES completion:nil];
  244. }
  245. /**
  246. 显示消息
  247. @param text <#text description#>
  248. */
  249. - (void)showAlertViewBackText:(NSString *)text
  250. {
  251. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:text preferredStyle:UIAlertControllerStyleAlert ];
  252. [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
  253. }]];
  254. // 3.显示alertController:presentViewController
  255. [self presentViewController:alert animated:YES completion:nil];
  256. }
  257. /**
  258. 返回
  259. */
  260. - (void)goHome {
  261. [self.navigationController popToRootViewControllerAnimated:YES];
  262. }
  263. /**
  264. 返回
  265. */
  266. - (void)goBack {
  267. if (delegate && onGoBack) {
  268. if ([delegate respondsToSelector:onGoBack] ) {
  269. [delegate performSelector:@selector(onGoBack) withObject:self];
  270. }
  271. }
  272. if (self.navigationController) {
  273. [self.navigationController popViewControllerAnimated:YES];
  274. }
  275. else {
  276. [self dismissViewControllerAnimated:YES completion:nil];
  277. }
  278. }
  279. /**
  280. 刷新导航单颜色
  281. */
  282. - (void)refreshNavColor {
  283. //导航栏背景色
  284. if (@available(iOS 15.0, *)) {
  285. UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
  286. appearance.backgroundColor = NavigationBarColor;
  287. appearance.backgroundEffect = nil;
  288. appearance.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
  289. self.navigationController.navigationBar.scrollEdgeAppearance = appearance;
  290. self.navigationController.navigationBar.standardAppearance = appearance;
  291. self.navigationController.navigationBar.hidden = NO;
  292. }else{
  293. [self.navigationController.navigationBar setBackgroundImage:mTopImage forBarMetrics:UIBarMetricsDefault];
  294. //设置导航栏文字颜色
  295. [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
  296. }
  297. self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
  298. }
  299. /**
  300. 导航栏清空
  301. */
  302. - (void)clearNavItem {
  303. self.navigationItem.leftBarButtonItem = nil;
  304. self.navigationItem.rightBarButtonItem = nil;
  305. }
  306. /**
  307. 图片按钮
  308. @param image <#image description#>
  309. @param target <#target description#>
  310. @param action <#action description#>
  311. @return <#return value description#>
  312. */
  313. - (UIButton *)getImageButton:(UIImage *)image target:(id)target action:(SEL)action {
  314. UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  315. rightBtn.frame = CGRectMake(0, 0, 40, 40);
  316. [rightBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
  317. int iWidth = image.size.width/2;
  318. int iHeight = image.size.height/2;
  319. UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
  320. imageView.frame = CGRectMake((40-iWidth)/2, (40-iHeight)/2, iWidth, iHeight);
  321. imageView.tag = @"1300";
  322. [rightBtn addSubview:imageView];
  323. return rightBtn;
  324. }
  325. /**
  326. UIBarButtonItem
  327. @param image <#image description#>
  328. @param target <#target description#>
  329. @param action <#action description#>
  330. @return <#return value description#>
  331. */
  332. - (UIBarButtonItem *)getImageBarItem:(UIImage *)image target:(id)target action:(SEL)action {
  333. //int iBtnWidth = IOS_7?40:40;
  334. UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  335. //rightBtn.frame = CGRectMake(0, 0, 40, 20);
  336. [rightBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
  337. [rightBtn setBackgroundImage:image
  338. forState:UIControlStateNormal];
  339. rightBtn.frame = CGRectMake(0, 0, 44, 20);
  340. // int iWidth = image.size.width/2;
  341. // int iHeight = image.size.height/2;
  342. // UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
  343. // imageView.frame = CGRectMake((iBtnWidth-iWidth)/2, (40-iHeight)/2, iWidth, iHeight);
  344. // imageView.tag = 1300;
  345. // [rightBtn addSubview:imageView];
  346. return [[UIBarButtonItem alloc] initWithCustomView:rightBtn] ;
  347. }
  348. /**
  349. UIBarButtonItem
  350. @param name <#name description#>
  351. @param target <#target description#>
  352. @param action <#action description#>
  353. @return <#return value description#>
  354. */
  355. - (UIBarButtonItem *)getTextBarItem:(NSString *)name target:(id)target action:(SEL)action {
  356. UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  357. rightBtn.frame = CGRectMake(0, 0, 40, 40);
  358. [rightBtn setTitle:name forState:UIControlStateNormal];
  359. [rightBtn setTitleColor:self.mTitleColor forState:UIControlStateNormal];
  360. rightBtn.titleLabel.font = [UIFont systemFontOfSize:15];
  361. [rightBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
  362. return [[UIBarButtonItem alloc] initWithCustomView:rightBtn] ;
  363. }
  364. /**
  365. 航栏左侧图片
  366. @param image <#image description#>
  367. @param target <#target description#>
  368. @param action <#action description#>
  369. */
  370. - (void)addLeftImageBtn:(UIImage *)image target:(id)target action:(SEL)action {
  371. self.navigationItem.leftBarButtonItem = [self getImageBarItem:image target:target action:action];
  372. }
  373. /**
  374. 航栏右侧图片
  375. @param image <#image description#>
  376. @param target <#target description#>
  377. @param action <#action description#>
  378. */
  379. - (void)addRightImageBtn:(UIImage *)image target:(id)target action:(SEL)action {
  380. self.navigationItem.rightBarButtonItem = [self getImageBarItem:image target:target action:action];
  381. }
  382. /**
  383. 航栏右侧图片数组
  384. @param array <#array description#>
  385. */
  386. - (void)addRightImageBtns:(NSArray *)array {
  387. if (!array || array.count == 0) {
  388. return;
  389. }
  390. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, array.count*40, 40)] ;
  391. for (int i = 0; i < array.count; i ++) {
  392. UIButton *btn = [array objectAtIndex:i];
  393. btn.frame = CGRectMake(i*40, 0, 40, 40);
  394. [view addSubview:btn];
  395. }
  396. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:view] ;
  397. }
  398. /**
  399. 导航栏右侧文本
  400. @param name <#name description#>
  401. @param target <#target description#>
  402. @param action <#action description#>
  403. */
  404. - (void)addRightTextBtn:(NSString *)name target:(id)target action:(SEL)action {
  405. self.navigationItem.rightBarButtonItem = [self getTextBarItem:name target:target action:action];
  406. }
  407. /**
  408. 标题
  409. @param title <#title description#>
  410. */
  411. - (void)setTitle:(NSString *)title {
  412. [super setTitle:title];
  413. mlbTitle.text = title;
  414. }
  415. /**
  416. UIView
  417. @return <#return value description#>
  418. */
  419. - (UIView *)getInputAccessoryView {
  420. UIView *inputView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 40)] ;
  421. inputView.backgroundColor = [UIColor colorWithWhite:0.8 alpha:1.0];
  422. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  423. btn.frame = CGRectMake(inputView.frame.size.width-50, 0, 50, inputView.frame.size.height);
  424. [btn setTitle:@"隐藏" forState:UIControlStateNormal];
  425. [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  426. btn.titleLabel.font = [UIFont systemFontOfSize:16];
  427. [btn addTarget:self action:@selector(onHideKeyboard) forControlEvents:UIControlEventTouchUpInside];
  428. [inputView addSubview:btn];
  429. return inputView;
  430. }
  431. /**
  432. 隐藏键盘
  433. */
  434. - (void)onHideKeyboard {
  435. [self.view endEditing:NO];
  436. }
  437. /**
  438. 显示logo
  439. @param iOffset <#iOffset description#>
  440. */
  441. - (void)showLogo:(int)iOffset {
  442. if (_mLogoView) {
  443. return;
  444. }
  445. int iWidth = 150;
  446. int iHeight = 130;
  447. _mLogoView = [[UIImageView alloc] initWithFrame:CGRectMake((self.view.frame.size.width-iWidth)/2, (self.view.frame.size.height-iHeight)/2+iOffset, iWidth, iHeight)];
  448. _mLogoView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
  449. _mLogoView.image = [UIImage imageNamed:@"default_logo.png"];
  450. [self.view addSubview:_mLogoView];
  451. }
  452. /**
  453. 隐藏logo
  454. */
  455. - (void)hideLogo {
  456. if (_mLogoView) {
  457. [_mLogoView removeFromSuperview];
  458. _mLogoView = nil;
  459. }
  460. }
  461. /**
  462. 加载进度条开始
  463. */
  464. - (void)startLoading
  465. {
  466. if (_mLoadView) {
  467. return;
  468. }
  469. _mLoadView = [[MBProgressHUD alloc] initWithView:self.view];
  470. if (mLoadMsg) {
  471. _mLoadView.mode = MBProgressHUDModeCustomView;
  472. _mLoadView.labelText = mLoadMsg;
  473. }
  474. [self.view addSubview:_mLoadView];
  475. // 判断加载框是否显示
  476. [UserInfoManager Share].isShowLoading=YES;
  477. [_mLoadView show:YES];
  478. }
  479. /**
  480. 加载进度条开始 新版1.0.0
  481. */
  482. - (void)startNewLoading
  483. {
  484. _mNewLoadView = [NewMBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
  485. // Change the background view style and color.
  486. _mNewLoadView.backgroundView.style = NewMBProgressHUDBackgroundStyleSolidColor;
  487. _mNewLoadView.backgroundView.color = [UIColor colorWithWhite:0.f alpha:0.1f];
  488. // 判断加载框是否显示
  489. [UserInfoManager Share].isShowLoading=YES;
  490. }
  491. /**
  492. 加载进度条结束
  493. */
  494. - (void)stopLoading
  495. {
  496. [UserInfoManager Share].isShowLoading=NO;
  497. [_mLoadView hide:YES];
  498. _mLoadView = nil;
  499. }
  500. /**
  501. 加载进度条结束 新版1.0.0
  502. */
  503. - (void)stopNewLoading
  504. {
  505. [UserInfoManager Share].isShowLoading=NO;
  506. //[_mNewLoadView hide:YES];
  507. [_mNewLoadView hideAnimated:YES];
  508. _mNewLoadView = nil;
  509. }
  510. /**
  511. 显示消息
  512. @param msg <#msg description#>
  513. */
  514. - (void)showMsg:(NSString *)msg
  515. {
  516. _mLoadView = [[MBProgressHUD alloc] initWithView:self.view];
  517. [self.view addSubview:_mLoadView];
  518. _mLoadView.mode = MBProgressHUDModeCustomView;
  519. _mLoadView.labelText = msg;
  520. [_mLoadView show:YES];
  521. [_mLoadView hide:YES afterDelay:1];
  522. _mLoadView = nil;
  523. }
  524. /**
  525. md5加密
  526. @param str <#str description#>
  527. @return <#return value description#>
  528. */
  529. - (NSString *) md5:(NSString *)str
  530. {
  531. const char *cStr = [str UTF8String];
  532. unsigned char result[16];
  533. CC_MD5( cStr, (CC_LONG)strlen(cStr), result );
  534. return [NSString stringWithFormat:@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
  535. result[0], result[1], result[2], result[3],
  536. result[4], result[5], result[6], result[7],
  537. result[8], result[9], result[10], result[11],
  538. result[12], result[13], result[14], result[15]
  539. ];
  540. }
  541. /**
  542. * 异常登录
  543. */
  544. - (void)showReLoginDialog{
  545. __weak id weakapp=Appdelegate;
  546. __weak id userShare = [UserInfoManager Share] ;
  547. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"异常登录" message:@"此用户已在其他移动端登录" preferredStyle:UIAlertControllerStyleAlert ];
  548. [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
  549. [userShare ClearUserData];
  550. [weakapp changeViewDidLogout];
  551. }]];
  552. // 3.显示alertController:presentViewController
  553. [self presentViewController:alert animated:YES completion:nil];
  554. }
  555. /**
  556. * 异常登录
  557. */
  558. - (void)showReLoginDialog:(NSString *)message {
  559. __weak id weakapp=Appdelegate;
  560. __weak id userShare = [UserInfoManager Share] ;
  561. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"异常登录" message:message preferredStyle:UIAlertControllerStyleAlert ];
  562. [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
  563. [userShare ClearUserData];
  564. [weakapp changeViewDidLogout];
  565. }]];
  566. // 3.显示alertController:presentViewController
  567. [self presentViewController:alert animated:YES completion:nil];
  568. }
  569. /**
  570. 无数据的view
  571. @param frame <#frame description#>
  572. @return <#return value description#>
  573. */
  574. - (UIView *)noDataViewByFrame:(CGRect)frame{
  575. UIView *noDataView = [[UIView alloc]init];
  576. noDataView.frame = frame;
  577. UIImageView *nodataImgView = [[UIImageView alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16,noDataView.frame.size.height/2-16,32,32)];
  578. [nodataImgView setImage:[UIImage imageNamed:@"icon_no_data"]];
  579. [noDataView addSubview:nodataImgView];
  580. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16-12,CGRectGetMaxY(nodataImgView.frame)+3,70, 25)];
  581. label.font = [UIFont systemFontOfSize:NoDataFontOfSize];
  582. label.text = @"无数据";
  583. label.numberOfLines = 2;
  584. label.textColor = [UIColor lightGrayColor];
  585. [noDataView addSubview:label];
  586. return noDataView;
  587. }
  588. /**
  589. 背景提示布局
  590. @param frame <#frame description#>
  591. @param str <#str description#>
  592. @return <#return value description#>
  593. */
  594. - (UIView *)backGroundPromptViewByFrame:(CGRect)frame promptStr:(NSString *)str{
  595. UIView *noDataView = [[UIView alloc]init];
  596. noDataView.frame = frame;
  597. UIImageView *nodataImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,32,32)];
  598. [nodataImgView setImage:[UIImage imageNamed:@"icon_no_data"]];
  599. nodataImgView.center = CGPointMake(noDataView.center.x, noDataView.center.y-30);
  600. [noDataView addSubview:nodataImgView];
  601. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,300,25)];
  602. label.textAlignment = NSTextAlignmentCenter;
  603. label.center = CGPointMake(noDataView.center.x,noDataView.center.y);
  604. label.font = [UIFont systemFontOfSize:NoDataFontOfSize];
  605. label.text = str;
  606. label.numberOfLines = 2;
  607. label.textColor = [UIColor lightGrayColor];
  608. [noDataView addSubview:label];
  609. return noDataView;
  610. }
  611. @end