UIProgressView 进度条
2015-09-01 21:00
501 查看
进度条的值在 0 1 之间,其他的和其余控件都差不多
通过.h中申明 bool 值 flag 来控制点击button时,进度条往哪个方向移动
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
// Override point for customization after application launch.
self.window= [[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];
self.window.backgroundColor=[UIColorwhiteColor];
//初始化UIProgressView 进度条,申明部分不在此处
pro = [[UIProgressViewalloc]initWithFrame:CGRectMake(100,100,
100,30)];
//初始化进度位置
pro.progress=0.5;
UIButton *but = [[UIButtonalloc]initWithFrame:CGRectMake(200,200,
50,50)];
[but setTitleColor:[UIColorredColor]
forState:normal];
but.backgroundColor=[UIColorblueColor];
//未按钮增加事件,点击按钮,增加或减少进度
[but addTarget:selfaction:@selector(act:)forControlEvents:UIControlEventTouchUpInside];
[self.windowaddSubview:but];
[self.windowaddSubview:pro];
[self.windowmakeKeyAndVisible];
returnYES;
}
-(void)act:(UIButton *)sender
{
if(flag==NO)
{
pro.progress=pro.progress+0.1;
if (pro.progress>=1) {
flag=YES;
}
}
else
{
pro.progress-=0.1;
if (pro.progress<=0) {
flag=NO;
}
}
}
通过.h中申明 bool 值 flag 来控制点击button时,进度条往哪个方向移动
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
// Override point for customization after application launch.
self.window= [[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];
self.window.backgroundColor=[UIColorwhiteColor];
//初始化UIProgressView 进度条,申明部分不在此处
pro = [[UIProgressViewalloc]initWithFrame:CGRectMake(100,100,
100,30)];
//初始化进度位置
pro.progress=0.5;
UIButton *but = [[UIButtonalloc]initWithFrame:CGRectMake(200,200,
50,50)];
[but setTitleColor:[UIColorredColor]
forState:normal];
but.backgroundColor=[UIColorblueColor];
//未按钮增加事件,点击按钮,增加或减少进度
[but addTarget:selfaction:@selector(act:)forControlEvents:UIControlEventTouchUpInside];
[self.windowaddSubview:but];
[self.windowaddSubview:pro];
[self.windowmakeKeyAndVisible];
returnYES;
}
-(void)act:(UIButton *)sender
{
if(flag==NO)
{
pro.progress=pro.progress+0.1;
if (pro.progress>=1) {
flag=YES;
}
}
else
{
pro.progress-=0.1;
if (pro.progress<=0) {
flag=NO;
}
}
}
相关文章推荐
- Codeforces 52A 123-sequence
- UITableView<三>
- UGUI基本控件(二)
- UIToolbar工具栏类
- 尽量用pass-by-reference-to-const(const引用)替换pass-by-value(传值)
- 尽量用pass-by-reference-to-const(const引用)替换pass-by-value(传值)
- UICollectionView 集合视图
- Android UI设计小知识——富文本
- setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key解决办法
- UIView与CALayer的区别
- UITableView<二>
- UIView动画和CAAnimation动画
- 页面之间传值方式的总结,五种方式,通知,block,代理,单例,NSUERDEFALUT,
- Android UI设计小知识——渐变色背景的制作
- HDU 5014 Number Sequence
- UITableView <一>
- UIView动画 防多星球环绕转动
- Android UI设计小知识——按钮背景的制作
- FragmentTabHost切换Fragment时避免UI重新加载
- POJ 3368 Frequent values RMQ ST算法/线段树