#import <UIKit/UIKit.h>
@interface LoginPrologueView : UIView<UIScrollViewDelegate>
@property(nonatomic,retain)UIButton* loginBtn;
@property(nonatomic,retain)UIButton* registerBtn;
@property(nonatomic,assign)CGRect bounds;
@property(nonatomic,retain)NSMutableArray* Array;
-(UIView*)init:(CGRect)bounds ImageViewArray:(NSMutableArray*)Array;
@end
//
// LoginPrologueView.m
// demo1.1
//
// Created by 61 on 16/7/11.
// Copyright (c) 2016年 oracle. All rights reserved.
//
#import "LoginPrologueView.h"
@interface LoginPrologueView()
{
}
@property(nonatomic,retain)UIScrollView* scrollView;
@property(nonatomic,retain)UIPageControl* pageControl;
@end
@implementation LoginPrologueView
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
-(UIView*)init:(CGRect)bounds ImageViewArray:(NSMutableArray*)Array;
{
if(self==nil)
{
return nil;
}
//设置视图大小
self.bounds=bounds;
//分配内存
self=[[LoginPrologueView alloc]initWithFrame:bounds];//为底层view视图分配内存
//添加滚动图层
CGRect imageFrame=CGRectMake(0, 0, self.bounds.size.width,(int)self.bounds.size.height*0.85);
UIImageView* view;
if(Array.count)
view=Array[0];
imageFrame=CGRectStandardize(view.frame);
CGRect scrollViewFrame=CGRectMake(0, 0, imageFrame.size.width,imageFrame.size.height);
self.scrollView=[[UIScrollView alloc]initWithFrame:scrollViewFrame];
self.scrollView.contentSize=CGSizeMake(Array.count*scrollViewFrame.size.width, scrollViewFrame.size.height);
//self.scrollView.backgroundColor=[UIColor redColor];
[self addSubview:self.scrollView];
for(int i=0;i<Array.count;i++)
{
view=Array[i];
//view3.image=[UIImage imageNamed:@"u0.png"];
//view.backgroundColor=[UIColor greenColor];
[self.scrollView addSubview:(UIImageView*)Array[i]];
}
self.scrollView.pagingEnabled=YES;
self.scrollView.showsHorizontalScrollIndicator=NO;
self.scrollView.delegate=self;
//pageControlView
CGRect pageControlFrame=CGRectMake((self.bounds.size.width-15*Array.count)/2, scrollViewFrame.size.height-70, 15*Array.count, 30);
self.pageControl=[[UIPageControl alloc]initWithFrame:pageControlFrame];
self.pageControl.numberOfPages=Array.count;
self.pageControl.currentPage=0;
self.pageControl.enabled=false;
[self addSubview:self.pageControl];
//LoginBtn
CGRect LoginBtnFrame=CGRectMake(0, scrollViewFrame.size.height, self.bounds.size.width/2, self.bounds.size.height-scrollViewFrame.size.height);
self.loginBtn=[[UIButton alloc]initWithFrame:LoginBtnFrame];
[self.loginBtn setTitle:@"登录" forState:UIControlStateNormal];
[self.loginBtn.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold"size:16]];
[self.loginBtn setTintColor:[UIColor blackColor]];
[self addSubview:self.loginBtn];
//RegisterBtn
CGRect registerBtnFrame=CGRectOffset(LoginBtnFrame, (int)self.bounds.size.width/2, 0);
self.registerBtn=[[UIButton alloc]initWithFrame:registerBtnFrame];
[self.registerBtn setTitle:@"注册" forState:UIControlStateNormal];
[self.registerBtn.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold"size:16]];
[self addSubview:self.registerBtn];
self.Array=Array;
//self.registerBtn.backgroundColor=[UIColor redColor];
return self;
}
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation
{
return UIStatusBarAnimationSlide;
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat scrollW=self.scrollView.frame.size.width;
self.pageControl.currentPage=(scrollView.contentOffset.x+scrollW*0.5)/scrollW;
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
UIImageView* view=self.Array[self.pageControl.currentPage];
if(view.backgroundColor==[UIColor blackColor])
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
else
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleDefault];
}
@end
//
// ViewController.m
// demo5.0
//
// Created by 61 on 16/7/12.
// Copyright (c) 2016年 oracle. All rights reserved.
//
#import "ViewController.h"
#import "LoginPrologueView.h"
@interface ViewController ()
@property(nonatomic,retain)LoginPrologueView* view2;
@property(nonatomic,retain)NSMutableArray* array;
@property(nonatomic,strong)UIImageView* image;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIScreen* screen=[UIScreen mainScreen];
CGRect bounds=screen.bounds;
self.array=[NSMutableArray new];
self.image=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0,bounds.size.width,bounds.size.height*0.93)];
self.image.image=[UIImage imageNamed: @"u0.png"];
self.image.backgroundColor=[UIColor whiteColor];
[self.array addObject:self.image];
//[self.view addSubview:self.view2];
[self.view addSubview:self.image];
self.image=[[UIImageView alloc]initWithFrame:CGRectMake(bounds.size.width, 0,bounds.size.width, bounds.size.height*0.93)];
self.image.image=[UIImage imageNamed:@"u10.png"];
self.image.backgroundColor=[UIColor blackColor];
[self.array addObject:self.image];
self.image=[[UIImageView alloc]initWithFrame:CGRectMake(bounds.size.width*2, 0,bounds.size.width, bounds.size.height*0.93)];
self.image.image=[UIImage imageNamed:@"u20.png"];
self.image.backgroundColor=[UIColor whiteColor];
[self.array addObject:self.image];
self.view2=[[LoginPrologueView alloc]init:bounds ImageViewArray:self.array];
//self.view2.backgroundColor=[UIColor grayColor];
[self.view2.loginBtn addTarget:self action:@selector(Login:withEvent:) forControlEvents:UIControlEventTouchUpInside];
[self.view2.registerBtn addTarget:self action:@selector(Register:withEvent:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.view2];
//self.view2.alpha=0.7;
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)Login:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"sss");
}
-(void)Register:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"aaa");
}
@end