分享一个简单的iphone自定义状态栏例子
来源:互联网 发布:手机淘宝店店招图片 编辑:程序博客网 时间:2024/06/05 04:21
不多说,上例子:
#import <Foundation/Foundation.h>//自定义状态栏,状态栏显示灰色背景并【indicator message】。用于耗时操作的状态栏信息提示//例如:访问网络时,提示正在获取网络数据,或者正在提交数据至服务器等提示@interface CHStatusBar : UIWindow {@privateUILabel *lblStatus;UIActivityIndicatorView *indicator;}-(void)showWithStatusMessage:(NSString*)msg;-(void)hide;@end
#import "CHStatusBar.h"@implementation CHStatusBar- (id) initWithFrame:(CGRect)frame{if (self = [super initWithFrame:frame]) {// 将窗体置于正确的位置和级别,就是比状态栏的级别稍高即可// 否则该窗体会被标准状态栏遮住,相当于web开发的zoomself.windowLevel = UIWindowLevelStatusBar + 1.0f;// 使窗体的框架和状态栏框架一致self.frame = [UIApplication sharedApplication].statusBarFrame;// 创建一个灰色图片背景,使他视觉上还是一个标准状态栏的感觉UIImageView* backgroundImageView = [[UIImageView alloc] initWithFrame:self.frame];backgroundImageView.image = [[UIImage imageNamed:@"statusbar_background.png"] stretchableImageWithLeftCapWidth:2 topCapHeight:0];[self addSubview:backgroundImageView];[backgroundImageView release];//创建一个progressindicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];indicator.frame = (CGRect) {.origin.x = 2.0f, .origin.y = 3.0f, .size.width = self.frame.size.height - 6, .size.height = self.frame.size.height - 6};indicator.hidesWhenStopped = YES;[self addSubview:indicator];//文字信息,用于和用户进行交互,最好能提示用户当前是什么操作lblStatus = [[UILabel alloc] initWithFrame:(CGRect){.origin.x = self.frame.size.height, .origin.y = 0.0f, .size.width = 200.0f, .size.height = self.frame.size.height}];lblStatus.backgroundColor = [UIColor clearColor];lblStatus.textColor = [UIColor blackColor];lblStatus.font = [UIFont boldSystemFontOfSize:10.0f];[self addSubview:lblStatus];}return self;}- (void) showWithStatusMessage:(NSString*) msg {if (!msg) return;lblStatus.text = msg;[indicator startAnimating];self.hidden = NO;}- (void) hide {[indicator stopAnimating];self.hidden = YES;}- (void) dealloc {[lblStatus release];[indicator release];[super dealloc];}@end
状态栏的背景图片找了个灰色的:
效果如下:
- 分享一个简单的iphone自定义状态栏例子
- 自定义iPhone的状态栏
- 一个简单的自定义事件的例子
- Iphone开发(3) 一个使用组合的简单例子
- iphone上自定义状态栏效果的实现
- SVM 自定义kernel的一个简单的code 例子
- 关于自定义特性的一个简单的小例子
- (原创)分享一个自定义的简单Retrofit下载工具
- IOS:最简单一个使用自定义的TableViewCell例子
- iPhone 添加状态栏图标及自定义状态栏
- 一个简单的例子
- 【项目经验】iphone自定义状态栏
- iOS-iphone自定义状态栏
- iOS-iphone自定义状态栏
- iPhone遮盖系统栏,实现自定义效果的状态栏
- iPhone遮盖系统栏,实现自定义效果的状态栏
- iPhone遮盖系统栏,实现自定义效果的状态栏
- iPhone遮盖系统栏,实现自定义效果的状态栏
- 融资向领头羊集中 深圳三成电商死于出生之年
- linux设备驱动程序学习笔记——container_of宏
- 选择新兴产业创业项目:四项原则与四个步骤
- UTF8和UNICODE和GBK编码
- 笔试题目小结
- 分享一个简单的iphone自定义状态栏例子
- 多线程访问共享内存的不加锁实现方式
- yaffs2文件系统制作
- 三大UML建模工具Visio、Rational Rose、PowerDesign的区别
- My first jsp page!
- 在用installshield制作安装包时如何在注册表中写文件关联
- Difference Between CALL TRANSACTION and SESSION METHOD
- 8.8 change bidirectional association to unidirectional (将双向关联改为单向关联)
- 编程技术面试的五大要点