MBProgressHUD自定义Loading图片
来源:互联网 发布:电脑健身软件 编辑:程序博客网 时间:2024/05/18 00:40
githud路径:https://github.com/jdg/MBProgressHUD
MBProgressHUD提供了一个很好的demo,在github上可以下载。
但是在loading中,如何才能自定义转圈图片呢?
我们需要自定义一个动画,即将一个image旋转即可,如果还需要在旋转图中心另加其他图,则要做些小动作了
代码如下:
MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:[HUDUtil getRealView:view] animated:animated]; hud.mode = MBProgressHUDModeCustomView; hud.offset = offset; //loading图片和动画 UIImage *image = [[UIImage imageNamed:@"loading圈"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; UIImageView *imgView = [[UIImageView alloc] initWithImage:image]; CABasicAnimation *anima = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; anima.toValue = @(M_PI*2); anima.duration = 1.0f; anima.repeatCount = 100; [imgView.layer addAnimation:anima forKey:nil]; UIImage *image_ye = [[UIImage imageNamed:@"loading叶"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; UIImageView *imgCenterView = [[UIImageView alloc] initWithImage:image_ye]; UIImageView *contentView = [[UIImageView alloc] initWithImage:image_ye]; [contentView addSubview:imgView]; [contentView addSubview:imgCenterView]; imgCenterView.center = contentView.center; imgView.center = contentView.center; hud.customView = contentView; //背景颜色 hud.bezelView.color = [UIColor colorWithHexString:@"0x000000"]; hud.bezelView.alpha = 0.5f; //背景宽高 CGFloat targetWidth; CGFloat targetHeight; CGFloat margin = 10.0f; targetWidth = imgView.width + margin*2; targetHeight = imgView.height + margin*2; CGSize newSize = CGSizeMake(targetWidth, targetHeight); hud.minSize = newSize; //颜色 hud.contentColor = [UIColor whiteColor]; hud.animationType = MBProgressHUDAnimationFade;
其中MBProgressHUD有一个view叫做bezelView,这个View就是承载loading圈圈的背景view,背景的颜色/透明度就可以直接通过caozuo bezeView
的响应值来修改。
而loading中,承载图片的view叫做customView,他是vezelView的一个子控件。
如若不需要负责的图片loading,而只需要一张图片转圈,那么就将该转圈图片放入一个UIImageView,再赋值给customView就可以了(hud.bezelVIew = imageView(承载转圈图片的view))
0 0
- MBProgressHUD自定义Loading图片
- MBProgressHUD更改成自定义图片
- MBProgressHUD开源loading状态
- MBProgressHUD开源loading状态
- MBProgressHUD自定义等待框
- iOS自定义对话框-MBProgressHUD
- MBProgressHUD多线程加载图片
- IOS内购时的Loading实现-MBProgressHUD
- 关于MBProgressHUD自定义帧动画
- 使用MBProgressHUD自定义加载动画
- 在线提供自定义的 loading 状态的图片
- 自定义显示加载等待图片插件(loading.git)
- 渐进填充图片的自定义loading加载样式
- 自定义loading 以及动画loading
- MBProgressHUD
- MBProgressHUD
- MBProgressHUD
- MBProgressHUD
- 微信小程序的发布配置及SSL证书配置
- 行为型设计模式-中介者模式
- 矩阵快速幂 总结
- Verilog语句简析
- 在应使用条件的上下文(在 'between@P1' 附近)中指定了非布尔类型的表达式。 ; unc
- MBProgressHUD自定义Loading图片
- 使用Nginx+Lua(OpenResty)开发高性能Web应用
- Python批量管理主机(paramiko、fabric与pexpect)
- Error:Execution failed for task':app:process DebugResources';
- Java学习路径
- iOS开发之Runtime常用示例总结
- 矩阵乘法的MPI并行计算
- Android 隐藏手机号中间四位
- Spring 容器的基本实现流程