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



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值