UI笔记基础篇一
一.标签Label
1.创建标签控件的属性:UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake:_,_,_,_;
2.设置标签的属性:
背景色,backgroundcolor.
文字颜色,字号,位置 TextColor, front, TextAlignment, UIFont systemFontOfSize,UIFont boldSystemFontOfSize
显示多行firstLabel.numberOfLines = 0
label高度自适应
1.先计算字符串所需要的高度
CGRect rect = [text boundingRectWithSize:CGSizeMake(200, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20]} context:nil];
2.把计算出来的高度 赋给 label 的高度
firstLabel.frame = CGRectMake(100, 100, 200, rect.size.height);
3.将标签添加到视图上
[self.view addSubview : label];
4.利用循环制作 乘法 标签。
二.按钮Button
1.创建按钮对象: UIButton *button = [[UIButton buttonWithType: UIButtonTypeSystem]; (创造的按钮图片会随系统改变成蓝色背景)
创建自定义按钮对象 :UIButton *button = [[UIButton buttonWithType: UIButtonTypeCustom];(按钮的大小与 图片大小保持一致)
2.设置按钮的属性:
背景色
位置:frame CGRectMake
标题:[button setTitle @“ 可以是数组,字符串等”forState:UIControlStateNormal];
3.添加点击事件:
[button addTarget: self action :@selector(click:) forControlEvents: UIControlEventsTouchUpInside];
4.将按钮添加到视图上
[self.view addSubview : button];
三.利用数组,循环创建按钮Button
1.创建一个数组 NSArray *titleArray = @[@"按钮1",@"按钮2",@"按钮3",@"按钮4",@"按钮5"];
2.利用for循环创建 for (int i = 0; i<titleArray.count; i++)
3.利用Button.tag 的值创造全局变量,调到点击事件中实现
//通过tag值在父视图里寻找子视图(如果类型不匹配,需要强转)。第二种就是全局变量
UIImageView *view = (UIImageView *)[self.view viewWithTag:100];
4.利用循环制作 九宫格 按钮。
四.UIView
1.创建UIView属性:UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake;
2.设置属性:
背景色
透明度:alpha
边框属性:layer layer.cornerRadius layer.masksToBounds
3.以View1为父视图创建子视图View2
4.动画方法 :
[UIView animateWithDuration:(NSTimeInterval) animations:<#^(void)animations#>];
[ UIView animateWithDuration:<#(NSTimeInterval)#> animations:<#^(void)animations#> completion:<#^(BOOL finished)completion#>
五.UIImage(展示一张图片) 和 UIImageView(展示一组动画)
1.创建UIImage对象 :
常用方法: [UIImage * image = [UIImage imageNamed:@“ ”];
通过路径找到:NSString *imagePath = [[NSBundle mainBundle]pathForResource:@"Icon-72@2x" ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
创建UIImageView对象 : [UIImageView *imageV = [[UIImageView alloc] initWithFrame :[UIScreen mainScreen].bouns];
2.图片填充背景色 : self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@“ ”];
3.将一组图片添加到数组中,创建一个图片动画
<1>.NSMutableArray *imageArray = [NSMutableArray array];
for (int i=1; i<19; i++)
{
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"DOVE %d",i]];
[imageArray addObject:image];
}
<2>.通过tag值在父视图里寻找子视图(如果类型不匹配,需要强转)。第二种就是全局变量
UIImageView *imageView = (UIImageView *)[self.view viewWithTag:100];
4.动画
添加动画图片: imageV.animationImages = imageArray;
执行动画时间: imageV.animationDuration = 1;
执行动画的次数:imageV.animationRepeatCount = 1;
执行动画:[imageV startAnimating];
5.计时器
1.计时器概念:每隔一段时间执行一次计时器方法,是否重复根据BOOL值自己定义(联想闹钟工作原理)
创建一个计时器全局变量NSTimer *_timer;
_timer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(方法) userInfo:nil repeats:YES];
六.UIView页面
1.引入跳转页面的头文件
2.跳转页面对象的创建 alloc init方法
3.跳转动画: modalTransitionStyle = UIModalTransitionStylePartialCurl;
4.界面跳转(模态跳转)
[self presentViewController:second animated:YES completion:^{
}];
触摸空白地方的方法
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
模态返回页面的方法
[self dismissViewControllerAnimated:YES completion:^{
}];
}
七. 代理 & 协议
1.第一步 : 写协议 , 写方法。@protocol 第二级视图+Delegate <NSObject>
2.第二步 : 创建代理属性 :@property(nonatomic,weak)id<第二级视图+Delegate>delegate;
3.第三步 : 调用第一步中写的方法,给方法的参数赋值。
4.第四步 : 让上一级页面遵守协议 :@interface ViewController ()<第二级视图+Delegate>
5.第五步 : 指定代理方 视图.delegate = self;
6.第六步 : 实现代理方法 ,获取方法三中传递过来的值,直接使用。
八.Block
1.第一步 :创建Block(参数传什么类型就定义什么类型)。@property(nonatomic,copy)void(^myBlock)(NSString *,UIColor *,NSSinteger);
2.第二步 :在下级页面返回上级时候,给Block赋值。self.myBlock( , );
3.第三步 :实现Block方法,获取第二步中传过来的值。
二级页面.myBlock = ^( , )
{
self.view.backgroundColor = color;
_label.text = name;
};
九.封装
一.TextField
1.文本输入框的属性创建。
2.设置属性:
边框样式:borderStyle firstField.borderStyle = UITextBorderStyleRoundedRect;
占位符: placeholder
字号大小:font
加密: secureTextEntry firstField.secureTextEntry = YES;
清除按钮: clearButtonMode firstField.clearButtonMode = UITextFieldViewModeAlways;
设置弹出键盘样式:keyboardType firstField.keyboardType = UIKeyboardTypeNumberPad;
3.自定义一级键盘
<1>创建一块View ,它的位置和宽不受数值的影响,只与高度有关。
<2>创建若干Button按钮,点击事件。
<3>最后一步很重要, firstField.inputView = view;
<4>二级键盘中,创建一个标签,firstField.inputAccessoryView = label;
4.点击空白,回收键盘
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[firstField endEditing:YES];}
二.UIDelegate代理
//系统键盘右下角按键的代理方法
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;}
//点击空白处 回收键盘
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self.view endEditing:YES];}
三.Notification通知
1.发送通知:[[NSNotificationCenter defaultCenter]postNotificationName:NSString object:id];
2.接收通知:
-(void)viewWillAppear:(BOOL)animated
{[super viewWillAppear:animated];
//创建一个监听者 (方法是否带参数取决于发送通知的时候有没有携带Object)
//name 发送方和监听方的name要保持一致,不然监听不到
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(reciveNotification:) name:@"1604" object:nil];
}
3.执行通知的方法
-(void)reciveNotification:(NSNotification *)notification
{
//notification.object是发通知的时候带过来的object self.view.backgroundColor = notification.object;
}
四.UIKeyBoardNotification 登录与注册界面
1. 当点击文本输入框的时候,系统会给键盘发送一个看不到的通知,然后键盘被告知将要被使用所以键盘才会升起来,我们只需要监听系统是否给键盘发通知 就可以。同理,当键盘回收的时候,还是系统发送一个回收键盘的通知
监听键盘升起
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBoardShow:) name:UIKeyboardWillShowNotification object:nil];
-(void)keyBoardShow:(NSNotification *)noti{
[UIView animateWithDuration:0.25 animations:^{_backView.frame = CGRectMake(0, 200, self.view.frame.size.width, 200);}];}
监听键盘回收
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBoardHidden:) name:UIKeyboardWillHideNotification object:nil];
-(void)keyBoardHidden:(NSNotification *)noti{
[UIView animateWithDuration:0.25 animations:^{_backView.frame = CGRectMake(0,300,self.view.frame.size.width,200);}];}
2.登录:
<1>储存数据的属性 NSUserDefaults *_defaults
将保存在_defaults中的大数组取出来 NSArray *userInArr = [ _defaults objectForKey:@“array”];
<2> 利用循环将大数组中的字典取出来 for (NSDictionary *dic in userInArr)
<3>利用字典里面的键key和值value将输入账号和密码取出
NSString *name = [dic objectForKey:@"name"];NSString *passWord = [dic objectForKey:@"passWord"];
<4>字符串比较验证账号和密码: isEqualToString:
<5>提示框 :UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"友情提示" message:@"用户名或密码不正确" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil]; [ alert show];
3.注册
<1>注册账号和密码保存到字典中:
NSMutableDictionary *userInDic = [[NSMutableDictionary alloc]init];
[userInDic setObject:_nameField.text forKey:@"name"];
[userInDic setObject:_passField.text forKey:@"passWord"];
[_UserInArray addObject:userInDic];字典装进大数组
[_defaults setObject:_UserInArray forKey:@"array"];
一.改变子视图的层次,应用在点击放大。
<1>-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{//改变self.view的子视图的层次
UIView *view = (UIView *)[self.view viewWithTag:100];
[self.view bringSubviewToFront:view];}
二.系统导航控制器
<1>.创建导航控制器
ViewController *vc = [[ViewController alloc]init];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
把导航控制器添加到window上(规则就是谁框架级别高,谁添加到window上)
self.window.rootViewController = nav;
<2>.导航控制器的构成:导航条(navigationBar) 导航条上的UI元素由UI navigationItem来构成 UI navigationItem分为左中右3部分(一般情况下,左右是按钮,中间是title)
设置导航条中间的titleview(导航条中间部分有2个属性,1个是title 1个是titleview,第2个是属性不可以同时设置)
1.self.navigationItem.title = @" ";
2.UIView *titleView = [[UIView alloc]initWithFrame:CGRectMake
self.navigationItem.titleView = titleView;
3.左右按钮
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithTitle:@"下一页" style:UIBarButtonItemStylePlain target:self action:@selector(nextPage)];
self.navigationItem.rightBarButtonItem = rightItem;
<3>.页面跳转
1.从当前页面push到下一页
[self.navigationController pushViewController:[[SecondViewController alloc]init] animated:YES];
2.从下级页面返回上一级界面
[self.navigationController popViewControllerAnimated:YES];
3.从下级页面返回第一级根界面
[self.navigationController popToRootViewControllerAnimated:YES];
3.跳转到指定页(只能跳转到当前页之前的页)
NSArray *viewControllerArr = self.navigationController.viewControllers;
[self.navigationController popToViewController:viewControllerArr[1] animated:YES];
<4>.改变导航栏背景颜色
self.navigationController.navigationBar.backgroundColor = [UIColor cyanColor];
self.navigationController.navigationBar.tintColor = [UIColor yellowColor];
三.自定义导航控制器
<1>.自定义导航条的步骤
1.先把系统的导航控制器创建出来
2.在把系统的导航条隐藏
3.在系统导航条的位置上,创建一个UIView
4.以这个UIView为父视图,创建所需要的UI控件(例如label,button...)
<2>.隐藏导航条:self.navigationController.navigationBarHidden = YES;
<3>.创建UIView,在UIView上创建UI控件
四.系统Tabbar控制器
<1>.系统创建Tabbar的步骤
1.创建两个数组,将被管理的页面和标题添加到数组中。
2.通过For循环创建ViewControllers
获取管理页面的类名:NSString *vcName = vcArray[i];
通过类名生成一个类:Class vcClass = NSClassFromString(vcName);
在通过类生成ViewController:UIViewController *vc = [[vcClass alloc]init];
最后创建一个导航控制器 : UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
将导航器添加到新创建的数组中:[navArray addObject:nav];
->self.viewControllers = navArray;
3.通过tabBarItem创建按钮和标题,图片
加上标题和图片:vc.tabBarItem.title = titleArray[i];vc.tabBarItem.image = [UIImage imageNamed:[NSString stringWithFormat:@"_%d.png",i]];vc.tabBarItem.selectedImage = [UIImage imageNamed:[NSString stringWithFormat:@"_c%d.png”,i]];
五.自定义Tabbar控制器
<1>.隐藏
self.tabBar.hidden=YES;
<2>.通过For循环创建ViewControllers
<3>.创建UIView
UIView *myBarView = [[UIView alloc]initWithFrame:self.tabBar.bounds];
<4>.以myBarview为 父视图,平均分布4个按钮
两种状态下的按钮
[button setImage:[UIImage imageNamed:[NSString stringWithFormat:@"tab_%d",i]] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:[NSString stringWithFormat:@"tab_c%d",i]] forState:UIControlStateSelected];
按钮的点亮和熄灭
if (i == 0)
{button.selected = YES;self.selectButton = button;}button.tag = i;
self.selectButton.selected = NO;
button.selected = YES;
self.selectButton = button;
self.selectedIndex = button.tag;
一.UISwitch开关控件
1.添加事件[switch addTarget:self action:@selector(onOrOff:) forControlEvents:UIControlEventValueChanged];
二.UISlider 滑动块控件
1.添加事件[slider addTarget:self action:@selector(changeAlpa:) forControlEvents:UIControlEventValueChanged];
三.UIAlertView 提示控件 /UIAlertViewViewController新版本提示控件
1.UIAlertView实例化:
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:@"" otherButtonTitles:@"",@"",nil];
[alert show];
2.事件实现方式:
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
if (buttonIndex == 0)通过下标值来改变
3.UIAlertViewViewController实例化:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"用户名错误" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
这个block就是点击取消按钮要做的事情
}];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
这个block就是点击取消按钮要做的事情
}];
[alert addAction:action1];
[alert addAction:action2];
[self presentViewController:alert animated:YES completion:^{
}];
四.UIActivityIndicatorView 加载网络数据的图标
1.实例化:UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activity.center = self.view.center;
开始加载
[activity startAnimating];
2.加载状态栏的图标
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
五.UIActionSheet从屏幕下方弹出来的选择框
1._sheet = [[UIActionSheet alloc]initWithTitle:@"请选择图片来源" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"照相机" otherButtonTitles:@"相册", nil];
2.-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{[_sheet showInView:self.view];}
3.实现方式:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
六.UIStepper计步器
1.stepper.minimumValue = 5;stepper.maximumValue = 200;
每次增加或减少的值 stepper.stepValue = 5;
长按 自动增加或减少stepper.autorepeat = YES;
增长到最大值后,继续增长变最小值,反之stepper.wraps = YES;
添加事件[stepper addTarget:self action:@selector(changeCount:) forControlEvents:UIControlEventValueChanged];
七.UIProgressView进度条
1.利用计时器读取进度条
_timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(changeProgress) userInfo:nil repeats:YES];
2.每隔0.1S 让进度条的值增加0.1
progressView.progress += 0.01;
if(progressView.progress == 1){
计时器停止[_timer invalidate];}
八.UITextView文本输入框
1.继承UIScrollview,所以文本默认是可以滚动的,这个控件通常情况下用在写一些建议,评论,投诉.....
textView.delegate = self;self.automaticallyAdjustsScrollViewInsets = NO;
九.UISegmentControl选项框
1. NSArray *items = @[@"消息",@"电话"];
UISegmentedControl *seg = [[UISegmentedControl alloc]initWithItems:items];
2.点击事件实现
if (seg.selectedSegmentIndex == 0)
一.Tap轻触
1.创建手势Tag
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
[_imageV addGestureRecognizer:tap];
二.longPress长按
1.创建手势longPress
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
设置长按时间longPress.minimumPressDuration = 1;
[_imageV addGestureRecognizer:longPress];
longPressd长按事件:
if (longPress.state == UIGestureRecognizerStateBegan)
{UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"请选择操作" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }];
[alert addAction:action1];
[self presentViewController:alert animated:YES completion:^{ }];
三.swipe轻扫
1.创建手势swipe
UISwipeGestureRecognizer *swipe1 = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe:)];
先规定清扫的方向
swipe1.direction = UISwipeGestureRecognizerDirectionLeft;
[_imageV addGestureRecognizer:swipe1];
-(void)swipe:(UISwipeGestureRecognizer *)swipe
{if (swipe.direction == UISwipeGestureRecognizerDirectionLeft)}
四.pinch捏合
1.创建手势pinch
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinch:)];
[_imageV addGestureRecognizer:pinch];
-(void)pinch:(UIPinchGestureRecognizer *)pinch
{//手指按到屏幕上
if (pinch.state == UIGestureRecognizerStateBegan)
{//先记录一下imageview最初的状态
_currentTransform = _imageV.transform;
}//手指开始捏合
if (pinch.state == UIGestureRecognizerStateChanged)
{//创建一个新的状态(在原有的状态下,通过手势的scale改变处新的 状态)
CGAffineTransform tr = CGAffineTransformScale(_currentTransform, pinch.scale, pinch.scale);
_imageV.transform = tr;
}//手指开始离开
if (pinch.state == UIGestureRecognizerStateEnded || pinch.state == UIGestureRecognizerStateCancelled)
{_lastScale = 1;_lastScale *= pinch.scale;}
五.rotation旋转
1.创建手势rotation
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotation:)];
[_imageV addGestureRecognizer:rotation];
-(void)rotation:(UIRotationGestureRecognizer *)rotation
{//实际上改变的是_imageV的角度 rotation
//先记录没有旋转的时候的角度 //用来记录旋转后的角度 CGFloat _changeRotation;
_imageV.transform = CGAffineTransformMakeRotation(rotation.rotation + _changeRotation);
if (rotation.state == UIGestureRecognizerStateBegan)
{//获取到最新角度
_changeRotation += rotation.rotation;
}
if (rotation.state == UIGestureRecognizerStateEnded)
{//手指离开屏幕的时候,依据最新角度重设_imageV.transform
_imageV.transform = CGAffineTransformMakeRotation(rotation.rotation);}
六.pan拖拽
1.创建手势pan
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(pan:)];
[_imageV addGestureRecognizer:pan];
-(void)pan:(UIPanGestureRecognizer *)pan
{//获取到手指在_imageV上的点的位置
CGPoint point = [pan translationInView:_imageV];
//修改手势的中心点
pan.view.center = CGPointMake(point.x + pan.view.center.x, point.y + pan.view.center.y);
//把最新的 点设为imageV的中心 (如果这句代码不写,会导致滑动的时候,图片飞起,等于固定了_imageV相对于自身的位置)
[pan setTranslation:CGPointMake(0, 0) inView:_imageV];}
一.UIScrollView滚动视图
<1>.创建ScrollView控件
UIScrollView *scrollview = [[UIScrollView alloc]initWithFrame:self.view.bounds];
[self.view addSubview:scrollview];
<2>.在ScrollView上创建imageView
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
imageView.image = image;[scrollview addSubview:imageView];
<3>.设置ScrollView大小和偏移量
scrollview.contentSize = CGSizeMake(image.size.width, image.size.height);
scrollview.contentOffset = CGPointMake(500, 0);
<4>ScrollView的五种代理方法
1.缩放的代理方法 (zoom)
2.拖拽的代理方法(Drag)
3.减速滑行的代理方法(Decelerating)
4.从运动开始到运动结束。都会一直被调用的方法-(void)scrollViewDidScrollToTop:(UIScrollView *)scrollView
5.回滚到顶部的代理方法(top)
二.创建scrollView
1._scrollView = [[UIScrollView alloc]initWithFrame:self.view.bounds];
_scrollView.contentSize = CGSizeMake(16*self.view.frame.size.width, self.view.frame.size.height);
设置分页属性_scrollView.pagingEnabled = YES;
2.设置代理_scrollView.delegate = self;
3.循环创建imageView
打开交互imageView.userInteractionEnabled = YES;
添加轻触手势
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapImage:)];
[imageView addGestureRecognizer:tap];
[_scrollView addSubview:imageView];
4.创建自动滚动的imageview
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(15*self.view.frame.size.width,0,self.view.frame.size.width, self.view.frame.size.height)];
给这张图添加第一张图片imageView.image = [UIImage imageNamed:@"圣斗士01.jpg"];
[_scrollView addSubview:imageView];
5.代理方法
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
_pc.currentPage = scrollView.contentOffset.x/scrollView.frame.size.width;
重设scrollView的偏移量为0,0
if (scrollView.contentOffset.x == 15*self.view.frame.size.width) {
scrollView.contentOffset = CGPointZero;
_pc.currentPage = 0;
}
}
三.创建小白点
<1>._pc = [[UIPageControl alloc]initWithFrame:CGRectMake((self.view.frame.size.width - 300)/2, 700, 300, 40)];
不让点击 _pc.enabled = NO;
设置总页数_pc.numberOfPages = 15;
设置当前页(页数是从0开始递增) _pc.currentPage = 0;
设置点的颜色 _pc.pageIndicatorTintColor = [UIColor whiteColor];
设置选中点点颜色_pc.currentPageIndicatorTintColor = [UIColor yellowColor];
[self.view addSubview:_pc];
四.创建计时器
1._timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(runLoopImage) userInfo:nil repeats:YES];
2.-(void)runLoopImage{
[UIView animateWithDuration:0.3 animations:^{
_scrollView.contentOffset = CGPointMake(_scrollView.contentOffset.x +self.view.frame.size.width, 0);
} completion:^(BOOL finished) {
_pc.currentPage = _scrollView.contentOffset.x/_scrollView.frame.size.width;
if (_scrollView.contentOffset.x == 15*self.view.frame.size.width) {
_scrollView.contentOffset = CGPointZero;
_pc.currentPage = 0;}}];}
浙公网安备 33010602011771号