UISlider/UISegmentedControl/UISetpper/UISwitch/UIProgressView/UIPageControl/UIImageView
2015-10-31 19:57
429 查看
#import "BFASRootViewController.h"
@interface BFASRootViewController ()
@end
@implementation BFASRootViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor =
[UIColor colorWithRed:0.957 green:0.879blue:0.809 alpha:1.000];
// UISlider,滑竿对象,
UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(20, 30,280, 20)];
slider.value = 0.5; // 默认的值
slider.minimumValue = 0.0f; // 最小的值
slider.maximumValue = 1.0f; // 最大的值
slider.minimumTrackTintColor = [UIColor yellowColor];
// 已过区域的颜色
slider.maximumTrackTintColor = [UIColor redColor]; // 未过区域的颜色
slider.thumbTintColor = [UIColor blueColor]; // 设置小滑块的颜色
[slider setThumbImage:[UIImage imageNamed:@"thumb_img.png"]forState:UIControlStateNormal];
// 设置图片
slider.minimumValueImage = [UIImage imageNamed:@"min_img.png"]; // 设置最左面的图片
slider.maximumValueImage = [UIImage imageNamed:@"max_img.png"]; // 设置最后面的图片
[slider addTarget:self action:@selector(sliderAction:)forControlEvents:UIControlEventValueChanged]; // 给slider添加监听事件
[self.view addSubview:slider];
[slider release];
// UISegmentedControl,分段控制器
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:@[@"聊天", @"视频", @"空间", @"微博"]];
segmentedControl.frame = CGRectMake(20, 80, 280, 30);
segmentedControl.momentary = NO; // 当选中之后是否保持选中状态
segmentedControl.selectedSegmentIndex = 2; // 默认选中哪一项
segmentedControl.tintColor = [UIColor purpleColor]; // 选中的项目的颜色
[segmentedControl insertSegmentWithTitle:@"插入的" atIndex:0animated:YES]; // 插入一项,通过下标
[segmentedControl addTarget:selfaction:@selector(segmentedControlAction:)forControlEvents:UIControlEventValueChanged]; // 绑定事件
[self.view addSubview:segmentedControl];
[segmentedControl release];
// UIStepper, 放大缩小按钮(大小不可更改)
UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(20,130, 100, 100)];
stepper.minimumValue = 1; // 最大值
stepper.maximumValue = 10; // 最小值
stepper.value = 5; // 当前值
stepper.stepValue = 2; // 每次变化的值
stepper.tintColor = [UIColor redColor];
// 颜色
[stepper addTarget:self action:@selector(stepperAction:)forControlEvents:UIControlEventValueChanged]; // 绑定事件
[self.view addSubview:stepper];
[stepper release];
// UISwitch,开关 (大小不可更改)
UISwitch *switch1 = [[UISwitch alloc] initWithFrame:CGRectMake(150, 130,100, 100)];
switch1.On = NO; // 设置默认状态
[switch1 setOn:YES animated:YES];
// 设置默认状态,可以选择使用动画效果
// API:In iOS 7, this property has no effect.
// API中说明,设置图片的属性,在iOS7中
switch1.onImage = [UIImage imageNamed:@"min_img"]; // 开启的图片
switch1.offImage = [UIImage imageNamed:@"max_img"]; // 关闭的图片
switch1.onTintColor = [UIColor blueColor]; // 开启的颜色
switch1.tintColor = [UIColor redColor];
// 本身的颜色
switch1.thumbTintColor = [UIColor brownColor]; // 块的颜色
[switch1 addTarget:self action:@selector(switchAction:)forControlEvents:UIControlEventValueChanged];
// 绑定事件
[self.view addSubview:switch1];
[switch1 release];
// UIProgressView,进度条
UIProgressView *progressView
= [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
progressView.frame = CGRectMake(20, 180, 280, 35);
progressView.progress = .5f; // 默认值
progressView.progressTintColor = [UIColor yellowColor]; // 走过区域的颜色
[progressView setProgress:0.8 animated:YES]; // 设置值,使用动画
[self.view addSubview:progressView];
[progressView release];
// UIPageControl,小圆点提示
UIPageControl *pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(20, 200, 280, 15)];
pageControl.backgroundColor = [UIColor colorWithWhite:.5f alpha:.5f];
pageControl.numberOfPages = 10; // 设置共有多少个小圆点,表示有多少个页面
pageControl.currentPage = 3; // 设置当前的小圆点
pageControl.hidesForSinglePage = YES; // 当只有一个小圆点的时候隐藏
pageControl.currentPageIndicatorTintColor = [UIColor blueColor]; //当前被选中的颜色
pageControl.pageIndicatorTintColor = [UIColor redColor]; //没有被选中的颜色
[pageControl addTarget:self action:@selector(pageControlAction:)forControlEvents:UIControlEventValueChanged]; // 绑定事件
[self.view addSubview:pageControl];
[pageControl release];
// UIImageView,播放动画
// 找到要播放的图片数组
NSMutableArray *imagesArray = [NSMutableArray array];
for (int i = 1;
i < 5; i++) {
// 通过名称找到图片,添加到数组中
[imagesArray addObject:[UIImage imageNamed:[NSStringstringWithFormat:@"saisai%d.jpg",
i]]];
}
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 230, 280, 280)];
imageView.image = [UIImage imageNamed:@"saisai1.jpg"]; // 设置显示的图片
imageView.animationImages = imagesArray; // 设置播放的图片数组
imageView.animationDuration = .5f; // 动画时间
[imageView startAnimating]; // 开始播放动画
[self.view addSubview:imageView];
[imageView release];
}
#pragma mark - UISlider的绑定事件
- (void)sliderAction:(UISlider *)sender
{
NSLog(@"%f", sender.value);
}
#pragma mark - UISegmentedControl的绑定事件
- (void)segmentedControlAction:(UISegmentedControl *)sender
{
// 获取到选中的下标
NSUInteger index = sender.selectedSegmentIndex;
// 获取到选中的文字,根据下标去获取
NSString *title = [sender titleForSegmentAtIndex:index];
NSLog(@"%@", title);
}
#pragma mark - UISteeper的绑定事件
- (void)stepperAction:(UIStepper *)sender
{
NSLog(@"%f", sender.value);
}
#pragma mark - UISwitch的绑定事件
- (void)switchAction:(UISwitch *)sender
{
NSLog(@"当前状态:%@",
sender.isOn == YES ? @"开启" : @"关闭");
}
#pragma mark - UIPageControl的绑定事件
- (void)pageControlAction:(UIPageControl *)sender
{
NSLog(@"点击了第%ld个小点点",
sender.currentPage);
}
@end
@interface BFASRootViewController ()
@end
@implementation BFASRootViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor =
[UIColor colorWithRed:0.957 green:0.879blue:0.809 alpha:1.000];
// UISlider,滑竿对象,
UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(20, 30,280, 20)];
slider.value = 0.5; // 默认的值
slider.minimumValue = 0.0f; // 最小的值
slider.maximumValue = 1.0f; // 最大的值
slider.minimumTrackTintColor = [UIColor yellowColor];
// 已过区域的颜色
slider.maximumTrackTintColor = [UIColor redColor]; // 未过区域的颜色
slider.thumbTintColor = [UIColor blueColor]; // 设置小滑块的颜色
[slider setThumbImage:[UIImage imageNamed:@"thumb_img.png"]forState:UIControlStateNormal];
// 设置图片
slider.minimumValueImage = [UIImage imageNamed:@"min_img.png"]; // 设置最左面的图片
slider.maximumValueImage = [UIImage imageNamed:@"max_img.png"]; // 设置最后面的图片
[slider addTarget:self action:@selector(sliderAction:)forControlEvents:UIControlEventValueChanged]; // 给slider添加监听事件
[self.view addSubview:slider];
[slider release];
// UISegmentedControl,分段控制器
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:@[@"聊天", @"视频", @"空间", @"微博"]];
segmentedControl.frame = CGRectMake(20, 80, 280, 30);
segmentedControl.momentary = NO; // 当选中之后是否保持选中状态
segmentedControl.selectedSegmentIndex = 2; // 默认选中哪一项
segmentedControl.tintColor = [UIColor purpleColor]; // 选中的项目的颜色
[segmentedControl insertSegmentWithTitle:@"插入的" atIndex:0animated:YES]; // 插入一项,通过下标
[segmentedControl addTarget:selfaction:@selector(segmentedControlAction:)forControlEvents:UIControlEventValueChanged]; // 绑定事件
[self.view addSubview:segmentedControl];
[segmentedControl release];
// UIStepper, 放大缩小按钮(大小不可更改)
UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(20,130, 100, 100)];
stepper.minimumValue = 1; // 最大值
stepper.maximumValue = 10; // 最小值
stepper.value = 5; // 当前值
stepper.stepValue = 2; // 每次变化的值
stepper.tintColor = [UIColor redColor];
// 颜色
[stepper addTarget:self action:@selector(stepperAction:)forControlEvents:UIControlEventValueChanged]; // 绑定事件
[self.view addSubview:stepper];
[stepper release];
// UISwitch,开关 (大小不可更改)
UISwitch *switch1 = [[UISwitch alloc] initWithFrame:CGRectMake(150, 130,100, 100)];
switch1.On = NO; // 设置默认状态
[switch1 setOn:YES animated:YES];
// 设置默认状态,可以选择使用动画效果
// API:In iOS 7, this property has no effect.
// API中说明,设置图片的属性,在iOS7中
switch1.onImage = [UIImage imageNamed:@"min_img"]; // 开启的图片
switch1.offImage = [UIImage imageNamed:@"max_img"]; // 关闭的图片
switch1.onTintColor = [UIColor blueColor]; // 开启的颜色
switch1.tintColor = [UIColor redColor];
// 本身的颜色
switch1.thumbTintColor = [UIColor brownColor]; // 块的颜色
[switch1 addTarget:self action:@selector(switchAction:)forControlEvents:UIControlEventValueChanged];
// 绑定事件
[self.view addSubview:switch1];
[switch1 release];
// UIProgressView,进度条
UIProgressView *progressView
= [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
progressView.frame = CGRectMake(20, 180, 280, 35);
progressView.progress = .5f; // 默认值
progressView.progressTintColor = [UIColor yellowColor]; // 走过区域的颜色
[progressView setProgress:0.8 animated:YES]; // 设置值,使用动画
[self.view addSubview:progressView];
[progressView release];
// UIPageControl,小圆点提示
UIPageControl *pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(20, 200, 280, 15)];
pageControl.backgroundColor = [UIColor colorWithWhite:.5f alpha:.5f];
pageControl.numberOfPages = 10; // 设置共有多少个小圆点,表示有多少个页面
pageControl.currentPage = 3; // 设置当前的小圆点
pageControl.hidesForSinglePage = YES; // 当只有一个小圆点的时候隐藏
pageControl.currentPageIndicatorTintColor = [UIColor blueColor]; //当前被选中的颜色
pageControl.pageIndicatorTintColor = [UIColor redColor]; //没有被选中的颜色
[pageControl addTarget:self action:@selector(pageControlAction:)forControlEvents:UIControlEventValueChanged]; // 绑定事件
[self.view addSubview:pageControl];
[pageControl release];
// UIImageView,播放动画
// 找到要播放的图片数组
NSMutableArray *imagesArray = [NSMutableArray array];
for (int i = 1;
i < 5; i++) {
// 通过名称找到图片,添加到数组中
[imagesArray addObject:[UIImage imageNamed:[NSStringstringWithFormat:@"saisai%d.jpg",
i]]];
}
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 230, 280, 280)];
imageView.image = [UIImage imageNamed:@"saisai1.jpg"]; // 设置显示的图片
imageView.animationImages = imagesArray; // 设置播放的图片数组
imageView.animationDuration = .5f; // 动画时间
[imageView startAnimating]; // 开始播放动画
[self.view addSubview:imageView];
[imageView release];
}
#pragma mark - UISlider的绑定事件
- (void)sliderAction:(UISlider *)sender
{
NSLog(@"%f", sender.value);
}
#pragma mark - UISegmentedControl的绑定事件
- (void)segmentedControlAction:(UISegmentedControl *)sender
{
// 获取到选中的下标
NSUInteger index = sender.selectedSegmentIndex;
// 获取到选中的文字,根据下标去获取
NSString *title = [sender titleForSegmentAtIndex:index];
NSLog(@"%@", title);
}
#pragma mark - UISteeper的绑定事件
- (void)stepperAction:(UIStepper *)sender
{
NSLog(@"%f", sender.value);
}
#pragma mark - UISwitch的绑定事件
- (void)switchAction:(UISwitch *)sender
{
NSLog(@"当前状态:%@",
sender.isOn == YES ? @"开启" : @"关闭");
}
#pragma mark - UIPageControl的绑定事件
- (void)pageControlAction:(UIPageControl *)sender
{
NSLog(@"点击了第%ld个小点点",
sender.currentPage);
}
@end
相关文章推荐
- iOS--UILabel的使用方法
- Maven: mvn -X 执行报错:No goals have been specified for this build.
- android UI学习 -- 设置界面的布局(包括style的使用,selector的使用,Checkbox自定义样式,菜单项的样式)
- DB表的关系及EF中Fluent API的使用
- 【从源码看Android】02MessageQueue的epoll原型
- Qt之统一的UI界面格式基调,漂亮的UI界面
- 【从源码看Android】03Android MessageQueue消息循环处理机制(epoll实现)
- OC UI学习中的笔记
- 杭电1159—Common Subsequence题解
- getRequestURI,getRequestURL的区别
- css3新UI
- True And False
- IOS 学习笔记之UI
- SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT
- 反射封装request参数为对象
- IOS笔记UI--进度条
- 【APUE】Chapter1 UNIX System Overview
- 【UI】锤子手机-坚果手机-文艺青年版-配色色号
- JS中的 toString 和 valueOf 方法
- iOS——UIPasteboard 粘贴板