1.首先,由於開發需要提示信息很多,無法顯示完整,需求要求,顯示完整,自動換行等功能;需要開發者自己重寫三方的代碼,代碼如下:
第一步驟:
你的工程中必須導入MBProgressHUD三方庫,下載地址:https://github.com/jdg/MBProgressHUD
當然這里也可以使用cocoapods進行集成第三方庫,簡單說一下步驟:
1.
//可以采用拖拽文件的形式,將文件夾拖到Dos窗口下即可
cd 工程路徑
2.
pod search 三方庫名(復制需要的三方庫版本)
3.
vim Podfile 在里面寫入
//這里8.0代表你的app最低支持的版本
platform :ios,‘8.0’
target :工程名 do
pod 'MBProgressHUD', '~> 0.9.2'
end
4.
sudo xcode-select --switch /Applications/Xcode.app
5.
pod install - -verbose - -no-repo-update
或者 : pod install
第二步驟:導入三方庫的頭文件
#import "MBProgressHUD.h"
第三步驟 : 如下代碼
/*
含有時間,文字,圖片提示框
適合多行文字顯示
*/
- (void)showMessageTitle:(NSString *)title andDelay:(int)timeInt andImage:(NSString *)imageStr{
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
hud.userInteractionEnabled = YES;
hud.backgroundColor = [UIColor clearColor];
hud.animationType = MBProgressHUDAnimationZoomOut;
hud.detailsLabelText = title;
hud.square = NO;
hud.mode = MBProgressHUDModeCustomView;
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
imageView.image = [UIImage imageNamed:imageStr];
hud.customView = imageView;
[hud hide:YES afterDelay:timeInt];
}
/*
含有時間,文字提示框
適合單行文字顯示
*/
- (void)showMessageTitle:(NSString *)title andDelay:(int)timeInt{
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
hud.userInteractionEnabled = YES;
hud.backgroundColor = [UIColor clearColor];
hud.animationType = MBProgressHUDAnimationZoomOut;
hud.detailsLabelText = title;
hud.square = NO;
hud.mode = MBProgressHUDModeText;
[hud hide:YES afterDelay:timeInt];
}
運行結果如圖: