您的位置:首页 > 产品设计 > UI/UE

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;
        }
    }
   
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: