011&012_UISwitch/UISlier/UIProgressView 开关、滑动条、进度条
2016-07-11 15:06
525 查看
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
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 9 学习系列:UIStackView
- 图片滑块 Sequence.js 实现带有视差滚动特效的图片滑块
- ugui batches
- [改善Java代码]正确使用String,StringBuffer,StringBuilder
- fiddler4 设置断点,修改request信息
- uitableview去掉最后一行cell的底线
- UI automator
- UVa - 10099 The Tourist Guide 并查集+贪心
- 如何引入GPUImage到自己的项目中
- PHP foreach的两种用法 as $key => $value
- duilib初始化无法获取控件位置(所有位置都为0)
- UIStack View如何让你的开发更简单(iOS 9和Xcode 7)
- 关于uIP移植以及部分特性解析和勘误
- HDU4285 circuits 插头dp
- Android测试详解_3-Building Instrumented Unit Tests-创建仪器单元测试
- uuid
- 安装CocoaPods
- TabBarController-跳出导航
- 关于CAShapeLayer的一些实用案例和技巧
- 编辑器 UEditor 百度富文本web编辑器