功能源代码(扇形进度)及Delegate运用在开放事件中、UINavigationController的封装
1:扇形进度视图及运用
首先先创建扇形的视图,传入进度值
#import <UIKit/UIKit.h> @interface LHProgressView : UIView @property (nonatomic) float progress; @end
#import "LHProgressView.h"
#define MinProgress (1.0 / 16.0) @implementation LHProgressView - (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor clearColor];
_progress = MinProgress;
}
return self;
} - (void)drawRect:(CGRect)rect
{ CGContextRef context = UIGraphicsGetCurrentContext(); CGContextFillPath(context);
CGRect aRect= CGRectMake(, , self.bounds.size.width - , self.bounds.size.height - );
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 0.9);
CGContextSetLineWidth(context, 2.0);
CGContextAddEllipseInRect(context, aRect);
CGContextDrawPath(context, kCGPathStroke); CGFloat centerX = self.bounds.size.width / ;
CGFloat centerY = self.bounds.size.height / ; UIColor *aColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.9];
CGContextSetFillColorWithColor(context, aColor.CGColor);
CGContextSetLineWidth(context, 0.0);
CGContextMoveToPoint(context, centerX, centerY);
CGContextAddArc(context, centerX, centerY, (self.bounds.size.width - ) / , - M_PI_2, - M_PI_2 + self.progress * *M_PI, );
CGContextClosePath(context);
CGContextDrawPath(context, kCGPathFillStroke); } - (void)setProgress:(float)progress
{
_progress = progress; if (_progress < MinProgress) {
_progress = MinProgress;
} if (_progress >= 1.0) { [self setNeedsDisplay];
[self removeFromSuperview]; } else { [self setNeedsDisplay]; } } @end
运用:
@property(nonatomic, strong)LHProgressView *progressView;
-(instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) { self.backgroundColor = [UIColor clearColor]; _progressView = [[LHProgressView alloc] init]; } return self;
}
- (void)setItemImageUrl:(NSString *)itemImageUrl
{
_itemImageUrl = itemImageUrl; BOOL imageExist = [[SDWebImageManager sharedManager] cachedImageExistsForURL:[NSURL URLWithString:itemImageUrl]]; if (_itemImageProgress == 1.0 || imageExist) { [_progressView removeFromSuperview]; } else { _progressView.bounds = CGRectMake(, , , );
_progressView.center = CGPointMake((self.bounds.size.width) / , (self.bounds.size.height) / );
[self addSubview:_progressView]; _progressView.progress = _itemImageProgress; } _itemImageView.image = _itemImage; [self resetSize]; __weak LHProgressView *progressView = _progressView;
__weak LHPhotoView *photoView = self;
NSInteger index = self.tag - ; [[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:itemImageUrl] options:SDWebImageRetryFailed | SDWebImageLowPriority progress:^(NSInteger receivedSize, NSInteger expectedSize) { if ([photoView.photoViewDelegate respondsToSelector:@selector(photoIsShowingPhotoViewAtIndex:)]) {
BOOL isShow = [photoView.photoViewDelegate photoIsShowingPhotoViewAtIndex:index]; if (isShow) {
if (receivedSize > kMinProgress) {
progressView.progress = (float)receivedSize/expectedSize;
}
} } if ([photoView.photoViewDelegate respondsToSelector:@selector(updatePhotoProgress:andIndex:)]) {
[photoView.photoViewDelegate updatePhotoProgress:(float)receivedSize/expectedSize andIndex:index];
} } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { if (image) {
if ([photoView.photoViewDelegate respondsToSelector:@selector(photoIsShowingPhotoViewAtIndex:)]) {
BOOL isShow = [photoView.photoViewDelegate photoIsShowingPhotoViewAtIndex:index]; if (isShow) {
photoView.itemImageView.image = image; [self resetSize];
} } if ([photoView.photoViewDelegate respondsToSelector:@selector(updatePhotoProgress:andIndex:)]) {
[photoView.photoViewDelegate updatePhotoProgress:1.0 andIndex:index];
}
} }]; }
注意:在break里面要先处理一下对象__weak LHProgressView *progressView = _progressView;上面也用到SDWebImage进行图片加载,并把进度赋值
2:Delegate运用在开放事件中
#import <UIKit/UIKit.h>
@class DMDropDownMenu; @protocol DMDropDownMenuDelegate <NSObject> - (void)selectIndex:(NSInteger)index AtDMDropDownMenu:(DMDropDownMenu *)dmDropDownMenu; @end
@interface DMDropDownMenu : UIView @property(nonatomic,assign)id<DMDropDownMenuDelegate>delegate; @end
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self tapAction];
_curText.text = self.listArr[indexPath.row];
if ([_delegate respondsToSelector:@selector(selectIndex:AtDMDropDownMenu:)]) {
[_delegate selectIndex:indexPath.row AtDMDropDownMenu:self];
}
}
运用时三步代码:
@interface ViewController ()<DMDropDownMenuDelegate>
@end DMDropDownMenu * dm1 = [[DMDropDownMenu alloc] initWithFrame:CGRectMake(, , , )];
dm1.delegate = self;
[self.view addSubview:dm1]; - (void)selectIndex:(NSInteger)index AtDMDropDownMenu:(DMDropDownMenu *)dmDropDownMenu
{
NSLog(@"dropDownMenu:%@ index:%d",dmDropDownMenu,index);
}
3:UINavigationController的封装
#import <UIKit/UIKit.h>
#import "UIColor+KSString.h"
@interface KSNavigationController : UINavigationController @end
#import "KSNavigationController.h" @interface KSNavigationController ()<UIGestureRecognizerDelegate> @end @implementation KSNavigationController - (void)viewDidLoad {
[super viewDidLoad];
//设置手势代理
self.interactivePopGestureRecognizer.delegate = self;
//设置NavigationBar
[self setupNavigationBar];
} //设置导航栏主题
- (void)setupNavigationBar
{
UINavigationBar *appearance = [UINavigationBar appearance];
//统一设置导航栏颜色,如果单个界面需要设置,可以在viewWillAppear里面设置,在viewWillDisappear设置回统一格式。
[appearance setBarTintColor:[UIColor getColor:@"fb9c0a"]]; //导航栏title格式
NSMutableDictionary *textAttribute = [NSMutableDictionary dictionary];
textAttribute[NSForegroundColorAttributeName] = [UIColor whiteColor];
textAttribute[NSFontAttributeName] = [UIFont systemFontOfSize:];
[appearance setTitleTextAttributes:textAttribute];
} - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if (self.viewControllers.count > ) {
viewController.hidesBottomBarWhenPushed = YES;
UIButton *backButton = [[UIButton alloc]initWithFrame:CGRectMake(, , , )];
[backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
[backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateHighlighted];
[backButton setImageEdgeInsets:UIEdgeInsetsMake(, -, , )];
[backButton addTarget:self action:@selector(popView) forControlEvents:UIControlEventTouchUpInside];
viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backButton];
}
[super pushViewController:viewController animated:animated];
} - (void)popView
{
[self popViewControllerAnimated:YES];
} //手势代理
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
return self.childViewControllers.count > ;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
4:MBProgressHUD的扩展1.0.0
//
// NSObject+MP.m
// MobileProject
//
// Created by wujunyang on 16/7/9.
// Copyright © 2016年 wujunyang. All rights reserved.
// #import "MBProgressHUD+MP.h" @implementation MBProgressHUD (MP) #pragma mark 显示错误信息
+ (void)showError:(NSString *)error ToView:(UIView *)view{
[self showCustomIcon:@"MBHUD_Error" Title:error ToView:view];
} + (void)showSuccess:(NSString *)success ToView:(UIView *)view
{
[self showCustomIcon:@"MBHUD_Success" Title:success ToView:view];
} + (void)showInfo:(NSString *)Info ToView:(UIView *)view
{
[self showCustomIcon:@"MBHUD_Info" Title:Info ToView:view];
} #pragma mark 显示一些信息
+ (MBProgressHUD *)showMessage:(NSString *)message ToView:(UIView *)view {
if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;
// 快速显示一个提示信息
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
hud.mode=MBProgressHUDModeText;
hud.label.text=message;
hud.label.font=CHINESE_SYSTEM();
//修改弹出窗的色
hud.bezelView.color =[UIColor whiteColor];
// 隐藏时候从父控件中移除
hud.removeFromSuperViewOnHide = YES;
//代表需要蒙版效果 hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
hud.backgroundView.color = [UIColor colorWithWhite:.f alpha:0.6f];
return hud;
} //加载视图
+(void)showLoadToView:(UIView *)view{
[self showMessage:@"加载中..." ToView:view];
} /**
* 进度条View
*/
+ (MBProgressHUD *)showProgressToView:(UIView *)view Text:(NSString *)text{
if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
hud.label.text=text;
hud.label.font=CHINESE_SYSTEM();
//修改弹出窗的色
hud.bezelView.color =[UIColor whiteColor];
// 代表需要蒙版效果
hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
hud.backgroundView.color = [UIColor colorWithWhite:.f alpha:0.6f];
return hud;
} //快速显示一条提示信息
+ (void)showAutoMessage:(NSString *)message{ [self showAutoMessage:message ToView:nil];
} //自动消失提示,无图
+ (void)showAutoMessage:(NSString *)message ToView:(UIView *)view{
[self showMessage:message ToView:view RemainTime: Model:MBProgressHUDModeText];
} //自定义停留时间,有图
+(void)showIconMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time{
[self showMessage:message ToView:view RemainTime:time Model:MBProgressHUDModeIndeterminate];
} //自定义停留时间,无图
+(void)showMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time{
[self showMessage:message ToView:view RemainTime:time Model:MBProgressHUDModeText];
} +(void)showMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time Model:(MBProgressHUDMode)model{ if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;
// 快速显示一个提示信息
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
hud.label.text=message;
hud.label.font=CHINESE_SYSTEM();
//模式
hud.mode = model;
// 隐藏时候从父控件中移除
hud.removeFromSuperViewOnHide = YES;
//修改弹出窗的色
hud.bezelView.color =[UIColor whiteColor];
// 代表需要蒙版效果
hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
hud.backgroundView.color = [UIColor colorWithWhite:.f alpha:0.6f];
// 隐藏时候从父控件中移除
hud.removeFromSuperViewOnHide = YES;
// X秒之后再消失
[hud hideAnimated:YES afterDelay:time]; } + (void)showCustomIcon:(NSString *)iconName Title:(NSString *)title ToView:(UIView *)view
{
if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;
// 快速显示一个提示信息
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
hud.label.text=title;
hud.label.font=CHINESE_SYSTEM();
// 设置图片
hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:iconName]]; // 再设置模式
hud.mode = MBProgressHUDModeCustomView; // 隐藏时候从父控件中移除
hud.removeFromSuperViewOnHide = YES; //修改弹出窗的色
hud.bezelView.color =[UIColor whiteColor];
// 代表需要蒙版效果
hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
hud.backgroundView.color = [UIColor colorWithWhite:.f alpha:0.6f]; // 3秒之后再消失
[hud hideAnimated:YES afterDelay:];
} + (void)hideHUDForView:(UIView *)view
{
if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;
[self hideHUDForView:view animated:YES];
} + (void)hideHUD
{
[self hideHUDForView:nil];
} @end
//
// MBProgressHUD+MP.h
// MobileProject
// 当引入MBProgressHUD时把下面的代码开放出来
// 使用如下:
// [MBProgressHUD showIconMessage:@"默认图,X秒后自动消失" ToView:self.view RemainTime:3];
// 如果没有视图则可以[MBProgressHUD showIconMessage:@"默认图,X秒后自动消失" ToView:nil RemainTime:3];
// [MBProgressHUD showMessage:@"纯文字,不自动消失" ToView:self.view]; 关掉则用:[MBProgressHUD hideHUD];//使用此方法进行隐藏
// MBProgressHUD *hud = [MBProgressHUD showProgressToView:nil Text:@"loading"]; 隐藏:[hud hide:YES];
// [MBProgressHUD showAutoMessage:@"自动消失"];
// [MBProgressHUD showSuccess:@"下载完成" ToView:self.view];
// [MBProgressHUD showError:@"下载失败" ToView:self.view];
// Created by wujunyang on 16/7/9.
// Copyright © 2016年 wujunyang. All rights reserved.
// #import <Foundation/Foundation.h> #import "MBProgressHUD.h" @interface MBProgressHUD (MP) /**
* 自定义图片的提示,3s后自动消息
*
* @param text 要显示的文字
* @param icon 图片地址(建议不要太大的图片)
* @param view 要添加的view
*/
+ (void)showCustomIcon:(NSString *)iconName Title:(NSString *)title ToView:(UIView *)view; /**
* 自动消失成功提示,带默认图
*
* @param success 要显示的文字
* @param view 要添加的view
*/
+ (void)showSuccess:(NSString *)success ToView:(UIView *)view; /**
* 自动消失错误提示,带默认图
*
* @param error 要显示的错误文字
* @param view 要添加的View
*/
+ (void)showError:(NSString *)error ToView:(UIView *)view; /**
* 自动消失提示,带默认图
*
* @param Info 要显示的文字
* @param view 要添加的View
*/
+ (void)showInfo:(NSString *)Info ToView:(UIView *)view; /**
* 文字+菊花提示,不自动消失
*
* @param message 要显示的文字
* @param view 要添加的View
*
* @return MBProgressHUD
*/
+ (MBProgressHUD *)showMessage:(NSString *)message ToView:(UIView *)view; /**
* 快速显示一条提示信息
*
* @param showAutoMessage 要显示的文字
*/
+ (void)showAutoMessage:(NSString *)message; /**
* 自动消失提示,无图
*
* @param message 要显示的文字
* @param view 要添加的View
*/
+ (void)showAutoMessage:(NSString *)message ToView:(UIView *)view; /**
* 自定义停留时间,有图
*
* @param message 要显示的文字
* @param view 要添加的View
* @param time 停留时间
*/
+(void)showIconMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time; /**
* 自定义停留时间,无图
*
* @param text 要显示的文字
* @param view 要添加的View
* @param time 停留时间
*/
+(void)showMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time; /**
* 加载视图
*
* @param view 要添加的View
*/
+ (void)showLoadToView:(UIView *)view; /**
* 进度条View
*
* @param view 要添加的View
* @param model 进度条的样式
* @param text 显示的文字
*
* @return 返回使用
*/
+ (MBProgressHUD *)showProgressToView:(UIView *)view Text:(NSString *)text; /**
* 隐藏ProgressView
*
* @param view superView
*/
+ (void)hideHUDForView:(UIView *)view; /**
* 快速从window中隐藏ProgressView
*/
+ (void)hideHUD; @end
功能源代码(扇形进度)及Delegate运用在开放事件中、UINavigationController的封装的更多相关文章
- [AS3]as3画笔实例实现橡皮擦功能源代码
[AS3]as3画笔实例实现橡皮擦功能源代码 //主容器 var main:Sprite = new Sprite(); main.mouseEnabled = false; addChild(mai ...
- Delegate(委托与事件)
Delegate可以当它是一个占位符,比如你在写代码的时候并不知道你将要处理的是什么.你只需要知道你将要引入的参数类型和输出类型是什么并定义它即可.这就是书本上所传达的方法签名必须相同的意思. 系统自 ...
- 在vue中关于element UI 中表格实现下载功能,表头添加按钮,和点击事件失效的解决办法。
因为在element 中表格是使用el-table的形式通过数据来支撑结构,所以,表格的样式没有自己写的灵活,所以有了没法添加按钮的烦恼.下面是解决的方法. 准备工作: 一.下载npm安装包两个 1. ...
- Jquery中bind(), live(), on(), delegate()四种注册事件的优缺点,建议使用on()
jquery中注册的事件,注册事件很容易理解偏差,叫法不一样.我第一反应就是如何添加事件,使用onclick之类的,暂时不讨论js注册事件的方法. 也看到园内前辈写过相关的帖子,但不是很详细,我找到了 ...
- Monkey源代码分析番外篇之Android注入事件的三种方法比較
原文:http://www.pocketmagic.net/2012/04/injecting-events-programatically-on-android/#.VEoIoIuUcaV 往下分析 ...
- Android开发之清除缓存功能实现方法,可以集成在自己的app中,增加一个新功能。
作者:程序员小冰,CSDN博客:http://blog.csdn.net/qq_21376985 Android开发之清除缓存功能实现方法,可以集成在自己的app中,增加一个新功能. 下面是一个效果图 ...
- canvas扇形进度圈动态加载
效果图如下:动态加载的 实现代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta cha ...
- 考勤输入导入OA平台与考勤统计报表导出功能源代码
注:以某某公司为例,每日签到时间为8点整 每日签退时间为17点30分 规则:公司签到签退时间在OA平台中可以视实际情况调整,当天有请假并通过工作流审批通过为有效,当天因公外出并通过工作流审批通过为 ...
- python实现netcat部分功能源代码
#!/opt/local/bin/python2.7 import sys import socket import getopt import threading import subprocess ...
随机推荐
- ECharts+BaiduMap+HT for Web网络拓扑图应用
前一篇谈及到了ECharts整合HT for Web的网络拓扑图应用,后来在ECharts的Demo中看到了有关空气质量的相关报表应用,就想将百度地图.ECharts和HT for Web三者结合起来 ...
- C#多线程技术总结(同步)
二.串行(同步): 1.lock.Monitor--注意锁定的对象必需是引用类型(string类型除外) 示例: private static object syncObject = new obje ...
- ROS 多台电脑间进行通信
版权声明:本文为博主原创文章,转载请标明出处: http://www.cnblogs.com/liu-fa/p/5773822.html 在我看来,ROS最牛逼的地方就是它的通信机制了,不仅仅是进程间 ...
- Ubuntu14.04安装JDK
下载oracle jdk包 从oracle官网下载jdk包,请选择Linux的tar包: 如果想使用命令行下载工具进行下载,可以先获得下载地址,然后运行curl进行下载: curl -L -O -H ...
- 关于C#基础
前几天帮人做个社交网站,还是用的控件方式,不过学习了ajax和一般处理程序ashx后,也用在了里面一些,今天回来继续写博客.继续上次总结下基础知识,学的内容多,总结的可能比较杂乱,分条总结为平时能自己 ...
- 实现了IEnumerable接口的GetEnumerator 即可使用 Foreach遍历,返回一个IEnumerator对象
#region 程序集 mscorlib.dll, v4.0.0.0 // C:\Program Files (x86)\Reference Assemblies\Microsoft\Framewor ...
- C# ACCESS数据库操作类
这个是针对ACCESS数据库操作的类,同样也是从SQLHELPER提取而来,分页程序的调用可以参考MSSQL那个类的调用,差不多的,只是提取所有记录的数量的时候有多一个参数,这个需要注意一下! usi ...
- Linux下的C编程实战
Linux下的C编程实战(一) ――开发平台搭建 1.引言 Linux操作系统在服务器领域的应用和普及已经有较长的历史,这源于它的开源特点以及其超越Windows的安全性和稳定性.而近年来, Linu ...
- Oracle to_char()函数的使用细则
Oracle to_char()函数的使用细则,学习连接 http://www.cnblogs.com/reborter/archive/2008/11/28/1343195.html
- 2015暑假多校联合---Mahjong tree(树上DP 、深搜)
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5379 Problem Description Little sun is an artis ...