BaseViewController.m 20 KB

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