UI UIView进度条,模拟手机充电功能
2015-04-17 09:58
399 查看
#import "JRProgres.h"
@implementation JRProgres
{
UIView * _contentView;
}
- (instancetype)initWithFrame:(CGRect)frame{// 重写构造方法一次创建3个视图,分别为最外层的绿框、子1白底、子2红条
self = [super
initWithFrame:frame];
if (self) {
//1.
设置边框为绿色
self.backgroundColor = [UIColor
greenColor];
UIView * bgview = [[UIView
alloc]initWithFrame:CGRectMake(2,
2, frame.size.width-4, frame.size.height-4)];
bgview.backgroundColor = [UIColor
whiteColor];
[self
addSubview:bgview];
// 2.设置内容条(边框子视图)
self.backgroundColor = [UIColor
greenColor];
_contentView = [[UIView
alloc]initWithFrame:CGRectMake(0,
2, 0, bgview.frame.size.height-4)];
_contentView.backgroundColor = [UIColor
redColor];
[bgview
addSubview:_contentView];
}
return
self;
}
- (void)setProgress:(int)flag{
// 1. get当前的frame
CGRect newFrame =
_contentView.frame;
int nowLength = ceil(newFrame.size.width);
int totalLength =
ceil(self.frame.size.width -4);
// 2. 重新给当前的frame设置宽度
if (flag) {
if ( nowLength<totalLength) {
int flag = newFrame.size.width < (self.frame.size.width
-4);// 检测是否超范围
NSLog(@"%g---%g---- %i()(",(newFrame.size.width -
4),self.frame.size.width -
4,flag);//打印结果
newFrame.size.width += (self.frame.size.width
- 4)/10.0;
}else{
NSLog(@"超出界限");
NSLog(@"%.15f---",(newFrame.size.width -
4));
}
}else{
if (nowLength - 1 >
0) {
newFrame.size.width -= (self.frame.size.width
- 4)/10.0;
}
}
// 3.重新给当前的frame设置宽度
_contentView.frame = newFrame;
}
- (void)autoMethod{
CGRect newFrame =
_contentView.frame;
int nowLength = ceil(newFrame.size.width);
int totalLength =
ceil(self.frame.size.width -4);
if ( nowLength<totalLength) {
newFrame.size.width += (self.frame.size.width
- 4)/10.0;
_contentView.frame = newFrame;
}
else {
newFrame.size.width =
0;
_contentView.frame = newFrame;
}
}
#import "AppDelegate.h"
#import "JRProgres.h"
@interface
AppDelegate ()
@end
@implementation AppDelegate
{
JRProgres * _pro;
}
UI UIView进度条,模拟手机充电功能
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
self.window = [[UIWindow
alloc]initWithFrame:[UIScreen
mainScreen].bounds];
self.window.backgroundColor
= [UIColor grayColor];
[self.window
makeKeyAndVisible];
_pro = [[JRProgres
alloc]initWithFrame:CGRectMake(0,
150,
250, 25)];
_pro.center =
self.window.center;
[self.window
addSubview:_pro];
UI UIView进度条,模拟手机充电功能UI UIView进度条,模拟手机充电功能UI
UIView进度条,模拟手机充电功能UI UIView进度条,模拟手机充电功能UI UIView进度条,模拟手机充电功能UI
UIView进度条,模拟手机充电功能
UIButton * leftButton = [UIButton
buttonWithType:UIButtonTypeCustom];
leftButton.frame =
CGRectMake(self.window.center.x-70,
200, 50,
45);
[leftButton setTitle:@"前进"
forState:UIControlStateNormal];
leftButton.backgroundColor = [UIColor
blueColor];
[self.window
addSubview:leftButton];
[leftButton addTarget:self
action:@selector(clickRight)
forControlEvents:UIControlEventTouchUpInside];
UI UIView进度条,模拟手机充电功能UI UIView进度条,模拟手机充电功能
UIButton * rightButton = [UIButton
buttonWithType:UIButtonTypeCustom];
rightButton.frame =
CGRectMake(self.window.center.x +
20, 200,
50, 45);
[rightButton
setTitle:@"后退"
forState:UIControlStateNormal];
rightButton.backgroundColor = [UIColor
blueColor];
[self.window
addSubview:rightButton];
[rightButton
addTarget:self
action:@selector(clickLeft)
forControlEvents:UIControlEventTouchUpInside];
UI UIView进度条,模拟手机充电功能UI UIView进度条,模拟手机充电功能UI
UIView进度条,模拟手机充电功能
[NSTimer
scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(autoMethod)
userInfo:nil
repeats:YES];
return
YES;
}
- (void)clickLeft{
[_pro
setProgress:0];
}
- (void)clickRight{
[_pro
setProgress:1];
}
- (void)autoMethod{
[_pro
autoMethod];
}
UI UIView进度条,模拟手机充电功能UI UIView进度条,模拟手机充电功能UI
UIView进度条,模拟手机充电功能
@end
@implementation JRProgres
{
UIView * _contentView;
}
- (instancetype)initWithFrame:(CGRect)frame{// 重写构造方法一次创建3个视图,分别为最外层的绿框、子1白底、子2红条
self = [super
initWithFrame:frame];
if (self) {
//1.
设置边框为绿色
self.backgroundColor = [UIColor
greenColor];
UIView * bgview = [[UIView
alloc]initWithFrame:CGRectMake(2,
2, frame.size.width-4, frame.size.height-4)];
bgview.backgroundColor = [UIColor
whiteColor];
[self
addSubview:bgview];
// 2.设置内容条(边框子视图)
self.backgroundColor = [UIColor
greenColor];
_contentView = [[UIView
alloc]initWithFrame:CGRectMake(0,
2, 0, bgview.frame.size.height-4)];
_contentView.backgroundColor = [UIColor
redColor];
[bgview
addSubview:_contentView];
}
return
self;
}
- (void)setProgress:(int)flag{
// 1. get当前的frame
CGRect newFrame =
_contentView.frame;
int nowLength = ceil(newFrame.size.width);
int totalLength =
ceil(self.frame.size.width -4);
// 2. 重新给当前的frame设置宽度
if (flag) {
if ( nowLength<totalLength) {
int flag = newFrame.size.width < (self.frame.size.width
-4);// 检测是否超范围
NSLog(@"%g---%g---- %i()(",(newFrame.size.width -
4),self.frame.size.width -
4,flag);//打印结果
newFrame.size.width += (self.frame.size.width
- 4)/10.0;
}else{
NSLog(@"超出界限");
NSLog(@"%.15f---",(newFrame.size.width -
4));
}
}else{
if (nowLength - 1 >
0) {
newFrame.size.width -= (self.frame.size.width
- 4)/10.0;
}
}
// 3.重新给当前的frame设置宽度
_contentView.frame = newFrame;
}
- (void)autoMethod{
CGRect newFrame =
_contentView.frame;
int nowLength = ceil(newFrame.size.width);
int totalLength =
ceil(self.frame.size.width -4);
if ( nowLength<totalLength) {
newFrame.size.width += (self.frame.size.width
- 4)/10.0;
_contentView.frame = newFrame;
}
else {
newFrame.size.width =
0;
_contentView.frame = newFrame;
}
}
#import "AppDelegate.h"
#import "JRProgres.h"
@interface
AppDelegate ()
@end
@implementation AppDelegate
{
JRProgres * _pro;
}
UI UIView进度条,模拟手机充电功能
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
self.window = [[UIWindow
alloc]initWithFrame:[UIScreen
mainScreen].bounds];
self.window.backgroundColor
= [UIColor grayColor];
[self.window
makeKeyAndVisible];
_pro = [[JRProgres
alloc]initWithFrame:CGRectMake(0,
150,
250, 25)];
_pro.center =
self.window.center;
[self.window
addSubview:_pro];
UI UIView进度条,模拟手机充电功能UI UIView进度条,模拟手机充电功能UI
UIView进度条,模拟手机充电功能UI UIView进度条,模拟手机充电功能UI UIView进度条,模拟手机充电功能UI
UIView进度条,模拟手机充电功能
UIButton * leftButton = [UIButton
buttonWithType:UIButtonTypeCustom];
leftButton.frame =
CGRectMake(self.window.center.x-70,
200, 50,
45);
[leftButton setTitle:@"前进"
forState:UIControlStateNormal];
leftButton.backgroundColor = [UIColor
blueColor];
[self.window
addSubview:leftButton];
[leftButton addTarget:self
action:@selector(clickRight)
forControlEvents:UIControlEventTouchUpInside];
UI UIView进度条,模拟手机充电功能UI UIView进度条,模拟手机充电功能
UIButton * rightButton = [UIButton
buttonWithType:UIButtonTypeCustom];
rightButton.frame =
CGRectMake(self.window.center.x +
20, 200,
50, 45);
[rightButton
setTitle:@"后退"
forState:UIControlStateNormal];
rightButton.backgroundColor = [UIColor
blueColor];
[self.window
addSubview:rightButton];
[rightButton
addTarget:self
action:@selector(clickLeft)
forControlEvents:UIControlEventTouchUpInside];
UI UIView进度条,模拟手机充电功能UI UIView进度条,模拟手机充电功能UI
UIView进度条,模拟手机充电功能
[NSTimer
scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(autoMethod)
userInfo:nil
repeats:YES];
return
YES;
}
- (void)clickLeft{
[_pro
setProgress:0];
}
- (void)clickRight{
[_pro
setProgress:1];
}
- (void)autoMethod{
[_pro
autoMethod];
}
UI UIView进度条,模拟手机充电功能UI UIView进度条,模拟手机充电功能UI
UIView进度条,模拟手机充电功能
@end
相关文章推荐
- 让Firefox支持Wap浏览器功能的插件 模拟手机上网功能
- Python3 小练习 模拟手机通讯录搜索功能
- 怎么模拟手机的返回键功能
- C++程序学习之实现手机通讯录功能模拟
- chrome模拟手机功能
- 怎么模拟手机的返回键功能
- 如何获取用户手机当前是否启动了android机的模拟位置功能
- 用Flex模拟智能手机表单输入的自动放大功能
- 【黑马.Net程序员】模拟手机缴费系统,功能不全面
- Android+struts2+json方式模拟手机登录功能
- Android+struts2+json方式模拟手机登录功能
- WebForm版demo,模拟手机Usb接口充电
- Android+struts2+json方式模拟手机登录功能
- 基于python的-模拟手机通讯录功能
- linux进度条功能模拟
- Android:Button同时设置OnLongClick、OnClick模拟相机长按聚焦 短按拍照的功能
- 手机充电原理分析及问题总结
- 用Java模拟出QQ桌面截图功能(未测试)
- 在app未开启时,实现对用户进行通知提醒功能总结(添加事件到手机系统日历并设置闹钟提醒)
- iOS手机功能汇总