IOS开发UI篇之──自定义加载等待框(MBProgressHUD)

ios-自己定义的加载框,类似于MBProgressHUD..zip 自己定义的加载框,类似于MBProgressHUD.绝对方便使用,想要啥加载效果就直接替换即可.后续会进行封装,欢迎继续关注 立即下载

这里介绍一下网友开源的MBProgressHUD类,实现等待框,


一、网上下载  MBProgessHUD 类文件,直接导入到工程即可

二、示例分析

在我的工程中示例如下:

1)在ShowImageViewController.h头文件代码如下:

#import <UIKit/UIKit.h>

#import "MBProgressHUD.h"


@interface ShowImageViewController : UIViewController<MBProgressHUDDelegate> {

    NSString        *_picUrlString;

    UIImageView     *_imageView;    

    MBProgressHUD    *_progressHUD;

}

@property (nonatomic, copy) NSString       *picUrlString;

@property (nonatomic, retain) IBOutlet UIImageView *imageView;

@property (nonatomic, retain) MBProgressHUD    *progressHUD;

//请求图片资源

-(void)imageResourceRequest;


//显示图片信息

-(void)displayImage:(UIImage *)image;


- (IBAction)dismissModealView:(id)sender;

-(void)removeModalView;

@end


2)在ShowImageViewController.m实现文件代码如下:

#import "ShowImageViewController.h"

#import <QuartzCore/QuartzCore.h>


@implementation ShowImageViewController

@synthesize picUrlString = _picUrlString;

@synthesize imageView = _imageView;

@synthesize progressHUD = _progressHUD;


- (void)viewDidLoad

{

    [super viewDidLoad];

    // Do any additional setup after loading the view from its nib.

    self.view.backgroundColor = [UIColor grayColor];

    self.view.alpha = 0.8;

    

    //设置图片为圆角

    self.imageView.backgroundColor = [UIColor clearColor];

  self.imageView.layer.borderColor = [UIColor lightGrayColor].CGColor;

  self.imageView.layer.borderWidth = 5.0;

    self.imageView.layer.masksToBounds = YES; 

    self.imageView.layer.cornerRadius = 10.0; 

}


-(void)viewWillAppear:(BOOL)animated

{

    [super viewWillAppear:animated];

    //当进入视图时,重新设置imageView

    [self.imageView setImage:nil];

    [self.imageView setFrame:CGRectMake(160, 200, 0, 0)];

    //显示加载等待框

    self.progressHUD = [[MBProgressHUD alloc] initWithView:self.view];

[self.view addSubview:self.progressHUD];

[self.view bringSubviewToFront:self.progressHUD];

self.progressHUD.delegate = self;

self.progressHUD.labelText = @"加载中...";

[self.progressHUD show:YES];

    

    //开启线程,请求图片资源

    [NSThread detachNewThreadSelector:@selector(imageResourceRequest) toTarget:self withObject:nil];

}

//请求图片资源

-(void)imageResourceRequest

{

    NSAutoreleasePool   *pool = [[NSAutoreleasePool alloc] init];

    //根据网络数据,获得到image资源

    NSData  *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:self.picUrlString]];

    UIImage *image = [[UIImage alloc] initWithData:data];

    [data release];

    //回到主线程,显示图片信息

    [self performSelectorOnMainThread:@selector(displayImage:) withObject:image waitUntilDone:NO];

    [image release];


    [pool release];

}

//显示图片信息

-(void)displayImage:(UIImage *)image

{

    //若self.progressHUD为真,则将self.progressHUD移除,设为nil

    if (self.progressHUD){

        [self.progressHUD removeFromSuperview];

        [self.progressHUD release];

        self.progressHUD = nil;

    }

    

    //图片慢慢放大动画效果

    [self.imageView setImage:image];

    [UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:0.5];

[self.imageView setFrame:CGRectMake(40, 100, 240, 160)];

[UIView commitAnimations];

        

}

- (void)viewDidUnload

{

    [self setImageView:nil];

    [super viewDidUnload];

    // Release any retained subviews of the main view.

    // e.g. self.myOutlet = nil;

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

    // Return YES for supported orientations

    return (interfaceOrientation == UIInterfaceOrientationPortrait);

}


- (IBAction)dismissModealView:(id)sender {   

    //设置定时器,当动画结束时,子视图从父视图中移除

    [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(removeModalView) userInfo:nil repeats:NO];

    

    [UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:0.5];

[self.imageView setFrame:CGRectMake(160, 200, 0, 0)];

[UIView commitAnimations];

    

}

-(void)removeModalView

{

    [self.view removeFromSuperview];

}

#pragma mark -

#pragma mark MBProgressHUDDelegate methods

- (void)hudWasHidden:(MBProgressHUD *)hud {

NSLog(@"Hud: %@", hud);

    // Remove HUD from screen when the HUD was hidded

    [self.progressHUD removeFromSuperview];

    [self.progressHUD release];

    self.progressHUD = nil;

}

- (void)dealloc

{

    [_picUrlString release];

    [_imageView release];

    [super dealloc];

}

@end


三、效果展示


四、总结

利用MBProgressHUD实现加载等待框,视觉效果大大提高

Qt OpenGL 3D 点云数据显示 在Qt中使用OpenGL显示3D点云数据是一个常见的需求,特别是在计算机视觉、机器人学和三维重建等领域。下面我将介绍一个基本的实现方案。 阅读详情

相关推荐

告别机床‘卡顿’!用C语言在STM32上实现连续小线段速度前瞻(附开源代码)

本文详细介绍了如何在STM32上使用C语言实现工业级连续小线段速度前瞻控制器,解决机床运动控制中的卡顿问题。通过轻量级算法框架设计和混合精度计算策略,显著提升加工效率和表面质量。文章包含开源代码和实战案例,帮助开发者快速掌握速度前瞻规划算法在嵌入式系统中的应用。

weixin_42571738的博客 195

ios MBProgressHUD使用以及自定义样式

关于MBProgressHUD的使用以及自定义样式,以及扩展MBProgressHUD之后从controller中提出来单写的接口

qiuqi12的博客 5729

STM32铅酸蓄电池内阻测试仪的交流阻抗测量与数据采集优化

本文深入探讨了基于STM32的铅酸蓄电池内阻测试仪设计,重点解析了交流阻抗测量原理与数据采集优化方案。通过采用1kHz交流小信号注入和数字相敏检波技术,实现对电池欧姆内阻的无损精准测量,并详细介绍了硬件前端调理、ADC过采样及系统标定等关键优化手段,有效提升了测量精度与稳定性。

weixin_29168393的博客 494

iOS自定义对话框

UIModalPresentationOverFullScreen 弹框

天道酬勤 1375

STM32硬件SPI驱动W5500以太网模块全流程(附避坑指南)

本文详细介绍了STM32硬件SPI驱动W5500以太网模块的全流程,包括硬件架构设计、SPI接口选型、官方驱动移植、网络协议栈配置与优化等关键步骤。通过实战案例和性能对比数据,帮助开发者快速实现稳定高效的网络连接,特别提供了常见问题排查指南和性能调优技巧。

weixin_29194693的博客 275

PyTorch 最新安装教程(2021-07-27)

PyTorch 最新安装教程(2021-07-27)前言1. 安装 Anaconda2. 检查显卡,更新驱动3. 创建PyTorch环境4. 配置清华TUNA镜像源5. 安装 PyTorch6. 测试 前言 万事开头难! 这句话又一次被我验证。 记得前不久刚陷入Tensorflow2.0的安装困境,这一次又被PyTorch 搞哭辽。 孩子太难了o(╥﹏╥)o,不过还好最终成功安装,感谢全网资源,感谢大佬们的博客!被我一次一次试了出来。 1. 安装 Anaconda Anaconda 是一个用于科学计算的 P

全网粉丝30W+,CSDN、稀土掘金人工智能领域签约作者,人工智能、大模型、Python 爬虫,商务合作,请私信沟通。 23万+

iOS 自定义的Loading框:JHLoadingView

上图: 看动图,请移至github:https://github.com/xjh093/JHLoadingView

豪冷的博客 1285

【图像拼接】论文精读:Content-Preserving Warps for 3D Video Stabilization(CPW)

论文题目:Content-Preserving Warps for 3D Video Stabilization——用于3D视频稳定的内容保持扭曲GSP、SPW、LPC等warp时多个项最小化问题的思想都是来自于这篇论文——CPW视频防抖。我们描述了一种从手持摄像机转换视频的技术,以便它看起来像是用定向相机运动拍摄的。我们的方法调整视频以出现,就好像它是从附近的视点拍摄的,允许模拟 3D 相机运动。通过仅针对感知合理性,而不是准确的重建,我们能够开发能够有效从单个源视频中重建动态场景的算法。

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 2万+

IOS开发UI篇之──自定义加载等待框(MBProgressHUD)【转】

来自:http://blog.csdn.net/pjk1129/article/details/6665603 这里介绍一下网友开源的MBProgressHUD类,实现等待框, 一、网上下载  MBProgessHUD 类文件,直接导入到工程即可 二、示例分析 在我的工程中示例如下: 1)在ShowImageViewController.h头文件代码如下: #import #

shareinfo2018 1004

基于毫米波生物感知雷达+STM32设计的独居老人居家监护系统(微信小程序)(192)

当前基于STM32设计的独居老人居家监护系统为独居老人提供一种简便、实时的健康监护服务。该系统通过集成多种传感器和功能模块,能够实时监测老人的生理指标、姿态以及室内环境状况,并通过微信小程序远程显示数据,当出现异常情况时及时发出报警提醒。

1万+

YOLOv11改进策略【Neck】| arXiv 2025 分层多头注意力HMHA 子空间拆分提多样 + 通道重排降冗余,强化目标检测精度

HMHA(Hierarchical Multi-Head Attention,分层多头注意力)旨在解决传统多头注意力(MHA)在图像恢复任务中的核心缺陷——特征冗余。传统MHA将通道均匀拆分给各个头,导致不同头学习的子空间信息相似,进而出现多头关注同一区域、忽略退化区域修复的问题,限制了模型的特征表达能力。HMHA通过“分层子空间拆分+通道重排序”策略,让每个头学习差异化、互补的上下文特征,从根源上缓解冗余,提升图像恢复任务中对复杂退化场景的特征捕捉能力。

Limiiiing的博客 785

读源码系列----MBProgressHUD(加载等待框)

阅读本文前,请先去下载源代码(传送门) MBProgressHUD是一个iOS的类,当等待后台进程执行时,可以显示出一个包含指示器或者标签的半透明的HUD。HUD是UIKit包中不允许开发者使用的UIProgressHUD的替代品。 使用前提 MBProgressHUD可以以ARC或者non-ARC方式运行在iOS的任何版本,它使用到下列Cocoa Touch框架 Foundati

寻亚楠的专栏 4852

【知识分享】IBIS 建模指南 05

本文详细阐述了IBIS模型创建过程中的关键技术和数据规范要求。主要内容包括:1. 数据完整性检查要点,强调I-V和V-T数据必须覆盖所有工艺角且匹配;2. 数据限制处理方法,介绍100/1000点限制下的两种数据筛选算法;3. 特殊数据处理技术,包括内部终端电阻调整和V-T表时间窗口选择;4. 高级关键字应用,涵盖[ModelSelector]、[Sub model]、[DiffPin]等复杂功能实现方法;5. 预加重缓冲器等特殊结构的建模方案。

一只豌豆象的博客 1601

自定义加载等待框(MBProgressHUD)

这里介绍一下网友开源的MBProgressHUD类,实现等待框, 一、网上下载  MBProgessHUD 类文件,直接导入到工程即可 二、示例分析 在我的工程中示例如下: 1)在ShowImageViewController.h头文件代码如下: #import  #import "MBProgressHUD.h" @interface ShowI

3596

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

上一篇: IOS开发缓存机制之—本地缓存机制
下一篇: IOS 数据存储
simbi
博客等级 码龄22年 86粉丝 24原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址