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