iOS引导页-初
2016-02-03 21:47
453 查看
学习iOS,今天试着做一个简单的引导页,由于的是新手,写的不好,不要见怪
首先创建一个引导页文件,这里我命名为GuideView
GuideView.h文件
GuideView.m文件
使用引导页
效果
![](http://img.blog.csdn.net/20160203214439932?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
后续会继续完善
首先创建一个引导页文件,这里我命名为GuideView
GuideView.h文件
#import <UIKit/UIKit.h> //自定义代理,实现按钮方法 @protocol GuideDelegate <NSObject> -(void)enter; @end @interface GuideView : UIScrollView<UIScrollViewDelegate> @property (nonatomic,weak) id<GuideDelegate>guidedelegate; @end
GuideView.m文件
#import "GuideView.h" #define PAGE_COUNT 2 #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width) #define SCREEN_HIEGHT ([UIScreen mainScreen].bounds.size.height) @interface GuideView(){ UIPageControl *page; } @end @implementation GuideView -(id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { self.bounces = NO; self.contentSize = CGSizeMake(SCREEN_WIDTH*PAGE_COUNT, SCREEN_HIEGHT); self.backgroundColor = [UIColor whiteColor]; self.showsHorizontalScrollIndicator = NO; self.pagingEnabled = YES; self.delegate = self; self.backgroundColor = [UIColor clearColor]; for (int i = 0; i < PAGE_COUNT; i++) { UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH * i, 0, SCREEN_WIDTH, SCREEN_HIEGHT)]; [view setBackgroundColor:[UIColor whiteColor]]; [view setImage:[UIImage imageNamed:[NSString stringWithFormat:@"guide%d",i+1]]]; [self addSubview:view]; if (i == 1) { UIButton *enter = [UIButton buttonWithType:UIButtonTypeSystem]; enter.frame = CGRectMake(SCREEN_WIDTH / 2 - 50, SCREEN_HIEGHT-100, 100, 50); [enter setTitle:@"Enter" forState:UIControlStateNormal]; [enter addTarget:self action:@selector(enterBtn) forControlEvents:UIControlEventTouchUpInside]; view.userInteractionEnabled = YES; [view addSubview:enter]; } } } return self; } //这个没有用,晓得问题的麻烦告诉一下 -(void)scrollViewDidScroll:(UIScrollView *)scrollView{ if (scrollView.contentOffset.x > SCREEN_WIDTH * 2 + 20) { [UIView animateWithDuration:0.3 animations:^{ self.alpha = 0.0; } completion:^(BOOL finished) { [self removeFromSuperview]; }]; } } -(void)enterBtn{ [self.guidedelegate enter]; } @end
使用引导页
#import "GuidePageView.h" #import "GuideView.h" #pragma mark 获取屏幕尺寸 #define SCREEN_FRAME ([UIScreen mainScreen].bounds) #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width) #define SCREEN_HRIGHT ([UIScreen mainScreen].bounds.size.height) @interface GuidePageView()<GuideDelegate> @end @implementation GuidePageView -(void)viewDidLoad{ [super viewDidLoad]; GuideView *g = [[GuideView alloc] initWithFrame:SCREEN_FRAME]; g.guidedelegate = self; [self.view addSubview:g]; } -(void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; } -(void)enter{ [self dismissViewControllerAnimated:YES completion:nil]; } @end
效果
后续会继续完善
相关文章推荐
- iOS命名规范
- iOS --- [持续更新中] iOS移动开发中的优质资源
- ios 获取当前wifi名称
- iOS开发:处理多点触摸与手势检测
- iOS上视频剪辑片段和添加背景音乐
- iOS中点击顶部statusBar让tableView回到第一行
- iOS开发之字符串显示不同的颜色
- iOS 循环语句的使用
- ios web 跳转
- iOS 9 学习系列:Contacts Framework
- iOS layer 的粒子视图和过度视图详解
- iOS Animation CATransaction事务 详解
- iOS开发之多线程GCD
- iOS:交换Button中图片与文字的左右位置
- How to use cocoa pod in your iOS project
- iOS开发之多线程技术
- iOS ----调用系统摄像捕捉人脸
- iOS中 最新支付宝支付(AliPay) 韩俊强的博客
- iOS中 最新支付宝支付(AliPay) 韩俊强的博客
- ios 类似安卓提示框自动消失