//
// ?ViewController.m
//輪播圖
//
// ?Created by lanou on 16/7/13.
// ?Copyright ? 2016年lanou. All rights reserved.
//
#import"ViewController.h"
@interfaceViewController()
#define screenWidth [UIScreen mainScreen].bounds.size.width
#define screenHeight [UIScreen mainScreen].bounds.size.height
@property(nonatomic,strong)UIPageControl*pageControl;
//滑動視圖UIScrollView,自帶了可滑動功能
@property(nonatomic,strong)UIScrollView*scrollView;
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
//創(chuàng)建初始化滑動視圖
// ???[UIScreen mainScreen].bounds包含了屏幕尺寸
self.scrollView=[[UIScrollViewalloc]initWithFrame:[UIScreenmainScreen].bounds];
for(NSIntegeri=0; i<6; i++) {
//根據(jù)i循環(huán)創(chuàng)建UIImageView,再添加到滑動視圖scrollView上面
UIImageView*imageView=[[UIImageViewalloc]initWithFrame:CGRectMake(i*screenWidth,0,screenWidth,screenHeight)];
NSString*imageName=nil;
if(i==5) {
imageName=@"1.jpg";
}else{
imageName=[NSStringstringWithFormat:@"%ld.jpg",i+1];
}
//加載響應(yīng)的圖片
UIImage*image=[UIImageimageNamed:imageName];
//設(shè)置圖片
imageView.image=image;
//將imageView添加到滑動視圖上
[self.scrollViewaddSubview:imageView];
}
//添加滑動視圖到屏幕上
[self.viewaddSubview:self.scrollView];
//設(shè)置滑動視圖的滑動區(qū)域contentSize
self.scrollView.contentSize=CGSizeMake(6*screenWidth,screenHeight);
//整屏翻轉(zhuǎn)
self.scrollView.pagingEnabled=YES;
//邊界回彈
self.scrollView.bounces=YES;
//設(shè)置代理土辩,代理是負(fù)責(zé)監(jiān)聽滑動視圖整個滑動過程的
self.scrollView.delegate=self;
//開啟一個定時器
// ???TimeInterval:時間間隔
//每隔一定的時間隔,target會去執(zhí)行selector這個方法
// ???[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(turnToNextImage) userInfo:(nil) repeats:YES];
self.pageControl=[[UIPageControlalloc]initWithFrame:CGRectMake(80,500,150,20)];
self.pageControl.numberOfPages=5;
[self.viewaddSubview:self.pageControl];
}
//定時器觸發(fā)的方法:跳轉(zhuǎn)到下一張圖片
-(void)turnToNextImage
{
//先獲取當(dāng)前圖片是第幾張
NSIntegerindex=self.scrollView.contentOffset.x/screenWidth;
//跳轉(zhuǎn)到下一張(設(shè)置偏移量)
[self.scrollViewsetContentOffset:CGPointMake((index+1)*screenWidth,0)animated:YES];
}
//滑動視圖滑動的時候調(diào)用
- (void)scrollViewDidScroll:(UIScrollView*)scrollView
{
// ???contentOffset是訪問到了滑動視圖的偏移量抢野,包含了x和y軸的偏移量
// ???setContentOffset:animated:
// ???NSLog(@"offset.x=%f,offset.y=%f",scrollView.contentOffset.x,scrollView.contentOffset.y);
}
//scrollView結(jié)束減速(停止)
- (void)scrollViewDidEndDecelerating:(UIScrollView*)scrollView
{
//判斷是否為最后一張
NSIntegerindex=scrollView.contentOffset.x/screenWidth;
// ???5表示最后一張圖片,如果是最后一張圖片就切換到第0張圖片(設(shè)置偏移量為0拷淘,0)
if(index==5) {
[scrollViewsetContentOffset:CGPointMake(0,0)animated:YES];
self.pageControl.currentPage=0;
}else{
self.pageControl.currentPage=index;
}
}
//滑動結(jié)束的時候調(diào)用
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView*)scrollView
{
//先獲取當(dāng)前下標(biāo)
NSIntegerindex=scrollView.contentOffset.x/screenWidth;
//是最后一張就設(shè)置偏移量為0,0
if(index==5) {
[scrollViewsetContentOffset:CGPointMake(0,0)animated:NO];
self.pageControl.currentPage=0;
}else{
self.pageControl.currentPage=index;
}
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
//
// ?ViewController.m
//彈框
//
// ?Created by lanou on 16/7/13.
// ?Copyright ? 2016年lanou. All rights reserved.
//
//UITextfeild:怎么獲取UITextFielld的文本指孤,怎么設(shè)置輸入框鍵盤類型启涯,設(shè)置占位字符串
#import"ViewController.h"
@interfaceViewController()
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)alertAction:(id)sender {
//彈框:UIAlertConteoller
// ???Title:大標(biāo)題
// ???message:小標(biāo)題
// ???preferredStyle:彈框樣式
UIAlertController*alertController=[UIAlertControlleralertControllerWithTitle:@"你有病"message:@"你有藥啊"preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction*okAction=[UIAlertActionactionWithTitle:@"確定"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction*_Nonnullaction) {
//按鈕按下要做的事情
NSLog(@"淮南師范學(xué)院");
}];
UIAlertAction*cancelAction=[UIAlertActionactionWithTitle:@"取消"style:(UIAlertActionStyleCancel)handler:nil];
//給彈框添加行為
[alertControlleraddAction:okAction];
[alertControlleraddAction:cancelAction];
[selfpresentViewController:alertControlleranimated:YEScompletion:nil];
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end