UIControl
2015-12-12 22:46
399 查看
//
// rootViewController.m
#import "secondViewController.h"
#import "rootViewController.h"
@interface rootViewController ()
@end
@implementation rootViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 创建一个数组作为分段控件的每个标题
NSArray *arr = @[@"汉子",@"妹纸",@"女汉纸",@"娘娘腔"];
// 创建一个分段控件
UISegmentedControl *seg = [[UISegmentedControl alloc]initWithItems:arr];
// 如果不设置frame 默认从(0,0)开始宽度根据最长的标题来定,且宽度统一
// 设置frame
seg.frame = CGRectMake(50, 100, 300, 30);
// 添加一个分段
// [seg insertSegmentWithTitle:@"heh" atIndex:3 animated:YES];
// 删除一个分段
// [seg removeSegmentAtIndex:3 animated:YES];
// //插入一个图片分段防止被渲染,segment 的数目会增加
//imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal,是防止被渲染的作用,不设置图片显示不出来。
// [seg insertSegmentWithImage:[[UIImageimageNamed:@"2"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]atIndex:1animated:YES];
// 设置一个图片
[seg setImage:[[UIImage imageNamed:@"1-1(被拖移).tiff.jpg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]forSegmentAtIndex:1];
// 重新设置分段标题
[seg setTitle:@"女妹纸" forSegmentAtIndex:3];
// 设置分段颜色
seg.tintColor = [UIColor redColor];
// 设置选中之后无颜色
// seg.momentary = YES;
// 设置单个控件的宽度
[seg setWidth:40 forSegmentAtIndex:3];
// 添加到视图上
[seg addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:seg];
[seg release];
}
- (void)change:(UISegmentedControl *)seg{
// 获取当前分段的下标
switch (seg.selectedSegmentIndex) {
case 0:
self.view.backgroundColor = [UIColor yellowColor];
break;
case 1:
self.view.backgroundColor = [UIColor greenColor];
break;
case 2:
self.view.backgroundColor = [UIColor orangeColor];
break;
case 3:
{
secondViewController *sec = [[secondViewController alloc]init];
// sec.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentViewController:sec animated:YES completion:^{
// 跳转到控制器后,完成视图加载再加载动画,红色背景先出现再播放动画
[sec.imageView startAnimating];
}];
[sec release];
break;
}
default:
break;
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
//
// secondViewController.m
/*
*视图控制器从无到显示在屏幕上的过程
1.视图控制器的初始化
2.加载视图 loadView
3.视图加载完毕viewDidLoad
4.视图即将出现viewWillAppear
5.视图已经出现viewDidappear
*/
// UIControl
// addTarget 方法是UIControl中声明的方法,因此,只有UIControl的子类才可以使用 addTarget 方法
//包含的子类:UIButton,UItextField,UISwitch,UISlider,UIPageControl,UISegmentedControl。
#import "secondViewController.h"
@interface secondViewController ()
@end
@implementation secondViewController
- (void)dealloc{
[_imageView release];
[super dealloc];
}
- (void)viewDidLoad {
[super viewDidLoad];
UISlider *slider = [[UISlider alloc]initWithFrame:CGRectMake(50, 50,290, 30)];
// slider.backgroundColor = [UIColor redColor];
// 设置显示条最小值
slider.minimumValue = 0;
// 设置显示条最大值
slider.maximumValue = 4;
// 设置滑块左边的颜色
slider.minimumTrackTintColor = [UIColor redColor];
// 设置滑块右边的颜色
slider.maximumTrackTintColor = [UIColor yellowColor];
// 设置最小值图片
slider.minimumValueImage = [UIImage imageNamed:@"1"];
// 设置滑块图片
[slider setThumbImage:[UIImage imageNamed:@"1"]forState:UIControlStateNormal];
// 设置滑块位置
slider.value = 2;
// 添加事件
[slider addTarget:self action:@selector(move:)forControlEvents:UIControlEventValueChanged];
// 设置按钮的颜色
slider.thumbTintColor = [UIColor orangeColor];
[self.view addSubview:slider];
// UIImageView动画
// 创建一个基本UIimageView 对象
UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(20,100, 330, 400)];
self.imageView = imageV;
imageV.backgroundColor = [UIColor redColor];
// image 会覆盖背景颜色,
// imageV.image = [UIImage imageNamed:@"1-1(被拖移).tiff"];
imageV.tag = 100;
// 创建一个数组用来存储动画图片
NSMutableArray *arr = [NSMutableArray array];
for (int i = 1; i < 9; i++) {
// 获取所有文件名
NSString *str = [NSString stringWithFormat:@"1-%d(被拖移).tiff",i];
// 将图片名转化为图片
UIImage *image = [UIImage imageNamed:str];
//将图片存进数组
[arr addObject:image];
}
//将数组作为动画图片
imageV.animationImages = arr;
// 设置动画时间
imageV.animationDuration = 2;
// 设置动画重复次数
imageV.animationRepeatCount = 100;
// 开始动画
[self.view addSubview:imageV];
// 不能在这里加载动画,浪费内存,自动禁止,要在 viewWillAppear中播放动画
//[imageV startAnimating];
// 创造一个开关控件
UISwitch *sw = [[UISwitch alloc]initWithFrame:CGRectMake(200, 600, 50,30)];
[self.view addSubview:sw];
[sw addTarget:self action:@selector(swit:)forControlEvents:UIControlEventTouchUpInside];
sw.on = YES;
// 给开关控件移除事件
// [sw removeTarget:self action:@selector(swit:)forControlEvents:UIControlEventTouchUpInside]
[slider release];
[imageV release];
[sw release];
}
- (void)viewWillAppear:(BOOL)animated{
// 先出现动画效果,在出现红色背景,是因为会出现视图覆盖,image 会覆盖背景颜颜色。
//self.imageView.backgroundColor = [UIColor grayColor];
UIImageView *imageV = (UIImageView *)[self.view viewWithTag:100];
[imageV startAnimating];
}
//实现开关控件的方法,参数即获取Switch本身
- (void)swit:(UISwitch *)swit{
// 判断开关状态
if (swit.on == YES) {
[self.imageView startAnimating];
}else{
[self.imageView stopAnimating];
self.imageView.image = [UIImage imageNamed:@"1-1(被拖移).tiff"];
}
}
//实现滑块事件
- (void)move:(UISlider *)moves{
self.imageView.animationDuration = moves.maximumValue - moves.value;
[self.imageView startAnimating];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
// rootViewController.m
#import "secondViewController.h"
#import "rootViewController.h"
@interface rootViewController ()
@end
@implementation rootViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 创建一个数组作为分段控件的每个标题
NSArray *arr = @[@"汉子",@"妹纸",@"女汉纸",@"娘娘腔"];
// 创建一个分段控件
UISegmentedControl *seg = [[UISegmentedControl alloc]initWithItems:arr];
// 如果不设置frame 默认从(0,0)开始宽度根据最长的标题来定,且宽度统一
// 设置frame
seg.frame = CGRectMake(50, 100, 300, 30);
// 添加一个分段
// [seg insertSegmentWithTitle:@"heh" atIndex:3 animated:YES];
// 删除一个分段
// [seg removeSegmentAtIndex:3 animated:YES];
// //插入一个图片分段防止被渲染,segment 的数目会增加
//imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal,是防止被渲染的作用,不设置图片显示不出来。
// [seg insertSegmentWithImage:[[UIImageimageNamed:@"2"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]atIndex:1animated:YES];
// 设置一个图片
[seg setImage:[[UIImage imageNamed:@"1-1(被拖移).tiff.jpg"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]forSegmentAtIndex:1];
// 重新设置分段标题
[seg setTitle:@"女妹纸" forSegmentAtIndex:3];
// 设置分段颜色
seg.tintColor = [UIColor redColor];
// 设置选中之后无颜色
// seg.momentary = YES;
// 设置单个控件的宽度
[seg setWidth:40 forSegmentAtIndex:3];
// 添加到视图上
[seg addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:seg];
[seg release];
}
- (void)change:(UISegmentedControl *)seg{
// 获取当前分段的下标
switch (seg.selectedSegmentIndex) {
case 0:
self.view.backgroundColor = [UIColor yellowColor];
break;
case 1:
self.view.backgroundColor = [UIColor greenColor];
break;
case 2:
self.view.backgroundColor = [UIColor orangeColor];
break;
case 3:
{
secondViewController *sec = [[secondViewController alloc]init];
// sec.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentViewController:sec animated:YES completion:^{
// 跳转到控制器后,完成视图加载再加载动画,红色背景先出现再播放动画
[sec.imageView startAnimating];
}];
[sec release];
break;
}
default:
break;
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
//
// secondViewController.m
/*
*视图控制器从无到显示在屏幕上的过程
1.视图控制器的初始化
2.加载视图 loadView
3.视图加载完毕viewDidLoad
4.视图即将出现viewWillAppear
5.视图已经出现viewDidappear
*/
// UIControl
// addTarget 方法是UIControl中声明的方法,因此,只有UIControl的子类才可以使用 addTarget 方法
//包含的子类:UIButton,UItextField,UISwitch,UISlider,UIPageControl,UISegmentedControl。
#import "secondViewController.h"
@interface secondViewController ()
@end
@implementation secondViewController
- (void)dealloc{
[_imageView release];
[super dealloc];
}
- (void)viewDidLoad {
[super viewDidLoad];
UISlider *slider = [[UISlider alloc]initWithFrame:CGRectMake(50, 50,290, 30)];
// slider.backgroundColor = [UIColor redColor];
// 设置显示条最小值
slider.minimumValue = 0;
// 设置显示条最大值
slider.maximumValue = 4;
// 设置滑块左边的颜色
slider.minimumTrackTintColor = [UIColor redColor];
// 设置滑块右边的颜色
slider.maximumTrackTintColor = [UIColor yellowColor];
// 设置最小值图片
slider.minimumValueImage = [UIImage imageNamed:@"1"];
// 设置滑块图片
[slider setThumbImage:[UIImage imageNamed:@"1"]forState:UIControlStateNormal];
// 设置滑块位置
slider.value = 2;
// 添加事件
[slider addTarget:self action:@selector(move:)forControlEvents:UIControlEventValueChanged];
// 设置按钮的颜色
slider.thumbTintColor = [UIColor orangeColor];
[self.view addSubview:slider];
// UIImageView动画
// 创建一个基本UIimageView 对象
UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(20,100, 330, 400)];
self.imageView = imageV;
imageV.backgroundColor = [UIColor redColor];
// image 会覆盖背景颜色,
// imageV.image = [UIImage imageNamed:@"1-1(被拖移).tiff"];
imageV.tag = 100;
// 创建一个数组用来存储动画图片
NSMutableArray *arr = [NSMutableArray array];
for (int i = 1; i < 9; i++) {
// 获取所有文件名
NSString *str = [NSString stringWithFormat:@"1-%d(被拖移).tiff",i];
// 将图片名转化为图片
UIImage *image = [UIImage imageNamed:str];
//将图片存进数组
[arr addObject:image];
}
//将数组作为动画图片
imageV.animationImages = arr;
// 设置动画时间
imageV.animationDuration = 2;
// 设置动画重复次数
imageV.animationRepeatCount = 100;
// 开始动画
[self.view addSubview:imageV];
// 不能在这里加载动画,浪费内存,自动禁止,要在 viewWillAppear中播放动画
//[imageV startAnimating];
// 创造一个开关控件
UISwitch *sw = [[UISwitch alloc]initWithFrame:CGRectMake(200, 600, 50,30)];
[self.view addSubview:sw];
[sw addTarget:self action:@selector(swit:)forControlEvents:UIControlEventTouchUpInside];
sw.on = YES;
// 给开关控件移除事件
// [sw removeTarget:self action:@selector(swit:)forControlEvents:UIControlEventTouchUpInside]
[slider release];
[imageV release];
[sw release];
}
- (void)viewWillAppear:(BOOL)animated{
// 先出现动画效果,在出现红色背景,是因为会出现视图覆盖,image 会覆盖背景颜颜色。
//self.imageView.backgroundColor = [UIColor grayColor];
UIImageView *imageV = (UIImageView *)[self.view viewWithTag:100];
[imageV startAnimating];
}
//实现开关控件的方法,参数即获取Switch本身
- (void)swit:(UISwitch *)swit{
// 判断开关状态
if (swit.on == YES) {
[self.imageView startAnimating];
}else{
[self.imageView stopAnimating];
self.imageView.image = [UIImage imageNamed:@"1-1(被拖移).tiff"];
}
}
//实现滑块事件
- (void)move:(UISlider *)moves{
self.imageView.animationDuration = moves.maximumValue - moves.value;
[self.imageView startAnimating];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
相关文章推荐
- marquee标签实现文字滚动
- [javase学习笔记]-3.6 break语句与continue语句
- 毕设第五周(阅读论文:The optimal sequenced route query)
- NGUI(隐藏面板)
- XSS quiz 1~5解题方案
- JS模块化工具requirejs简易教程
- (八十七)break和continue语句、以及goto语句
- UIButton
- 使用Fluent API进行实体映射【Code-First系列】
- easyUI——datebox验证和自定义取消按钮
- iOS UIFont 字体名字大全
- UITableView-FDTemplateLayoutCell----UITableViewCell高度计算的那些事
- bug: wtforms-tornado遇上tornado self.request.body
- APUE:实际用户ID和有效用户ID(euid)
- iOS Xcode7 Xib 动态计算UITableViewCell高度详解
- java-GUI
- android - Adding Recent Query Suggestions
- android-studio中运行项目出现 java.exe'' finished with non-zero exit value 2错误
- UIView的小小总结
- UESTC 1264 人民币的构造 数论