iOS开发中,MBProgressHUD提示自动换行

 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];

}

 

运行结果如图:

 

 

 

posted @ 2017-05-27 16:05  KennyHito  阅读(2363)  评论(0编辑  收藏  举报