標籤:fan delay 地址 init 版本 import clear 拖拽 bsp
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];
}
運行結果:
iOS開發中,MBProgressHUD提示自動換行