011&012_UISwitch/UISlier/UIProgressView 开关、滑动条、进度条

UISwitch:width和height不可以改变(80,40)

UISlider和ProgressView的高度不可以改变:40


UISwitch:开关

UISlider:调节音量等

ProgressView:没有方法,进度条,用于加载等;



定义类代码:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

{

    UIProgressView* _processView;

    UISlider* _slider;

    UISwitch* _mySwitch;

    

}

@property(retain,nonatomic)UIProgressView* processView;

@property(retain,nonatomic)UISlider* slider;

@property(retain,nonatomic)UISwitch* mySwitch;

@end


实现代码:

//

//  ViewController.m

//  review0711_3

//

//  Created by Encore on 16/7/11.

//  Copyright © 2016 trauson. All rights reserved.

//


#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController

@synthesize slider=_slider;

@synthesize processView=_processView;

@synthesize mySwitch=_mySwitch;



- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    

    _slider=[[UISlider alloc]initWithFrame:CGRectMake(50, 100, 200, 40)];

    _processView=[[UIProgressView alloc]initWithFrame:CGRectMake(10, 200, 300, 40)];

    _mySwitch=[[UISwitch alloc]initWithFrame:CGRectMake(20, 50, 80, 40)];

    

    //定义Switch按钮

    // _mySwitch.on=YES;

    [_mySwitch setOn:YES animated:YES];

    

    _mySwitch.onTintColor=[UIColor redColor];

    _mySwitch.thumbTintColor=[UIColor blueColor];

    _mySwitch.tintColor=[UIColor orangeColor];

    

    [_mySwitch addTarget:self action:@selector(swNO) forControlEvents:UIControlEventValueChanged];

    

    

    //定义进度条

    _processView.progress=0.7;

    _processView.trackTintColor=[UIColor redColor];

    _processView.progressTintColor=[UIColor blackColor];

    

    

    //定义Slider,滑动条

    _slider.maximumValue=100;

    _slider.minimumValue=-10;

    _slider.value=20;

    [_slider addTarget:self action:@selector(move) forControlEvents:UIControlEventValueChanged];

   

    

    

    

    [self.view addSubview:_slider];

    [self.view addSubview:_processView];

    [self.view addSubview:_mySwitch];

}


-(void)swNO

{

    if (_mySwitch.isOn==YES) {

        NSLog(@"按钮被选中");

    }

    else

    {

        NSLog(@"按钮未被选中");

    }

}


-(void)move

{

    _processView.progress=(_slider.value-_slider.minimumValue)/(_slider.maximumValue-_slider.minimumValue);

    NSLog(@"the value is %f",_slider.value);

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end



阅读更多
个人分类: IOS学习之路
想对作者说点什么? 我来说一句

最简单的进度条(UIProgressView)

2016年03月31日 61KB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭