滚动视图 自封装

#import "ViewController.h"

#import "ImageScrollView.h"

#import "AppDelegate.h"

#import "RootViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    NSArray *imgNameArr = @[@"guidePage1",@"guidePage2",@"guidePage3"];

    CGRect confirmBtnFrame = CGRectMake(self.view.frame.size.width - 200, 80, 150, 40);

    ImageScrollView *guide = [[ImageScrollView alloc]initWithFrame:self.view.frame style:ImageScrollType_Guide images:imgNameArr confirmBtnTitle:@"立即体验" confirmBtnTitleColor:[UIColor blueColor] confirmBtnFrame:confirmBtnFrame autoScrollTimeInterval:0 delegate:self];

    //添加滚动式图

    [self.view addSubview:guide];

    //添加分页控件

    [guide addPageControlToSuperView:self.view];

}

-(void)experienceDidHandle{

    RootViewController *rootVC = [[RootViewController alloc] init];

    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;

    app.window.rootViewController = rootVC;

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

@end


无线轮播

#import "RootViewController.h"

#import "ImageScrollView.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    NSArray *arr = @[@"man1.jpg",@"man2.jpg",@"man3.jpg",@"man4.jpg"];


    ImageScrollView *banner = [[ImageScrollView alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 350) style:ImageScrollType_Banner images:arr confirmBtnTitle:nil confirmBtnTitleColor:nil confirmBtnFrame:CGRectZero autoScrollTimeInterval:3 delegate:self];

    [self.view addSubview:banner];


}

-(void)bannerImageDidHandleWithIndex:(NSInteger)index{

    NSLog(@"点击了第%ld张图",index+1);

}





#import "ViewController.h"

#import "AppDelegate.h"

#import "ImageScrollView.h"

#import "TabBarViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];


    NSArray *imgNameArr = @[@"guidePage1",@"guidePage2",@"guidePage3"];


    CGRectconfirmBtnFrame =CGRectMake(self.view.frame.size.width-200,80,150,40);


    ImageScrollView *guide = [[ImageScrollView alloc]initWithFrame:self.view.frame style:ImageScrollType_Guide images:imgNameArr confirmBtnTitle:@"立即体验" confirmBtnTitleColor:[UIColor redColor] confirmBtnFrame:confirmBtnFrame autoScrollTimeInterval:3 delegate:self];


    //添加滚动式图


    [self.viewaddSubview:guide];


    //添加分页控件


    [guideaddPageControlToSuperView:self.view];


}

-(void)experienceDidHandle{


    TabBarViewController *tabVC = [[TabBarViewController alloc] init];


    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;


    app.window.rootViewController = tabVC;


}

@end


//控制器初始化

    FirstViewController *firstVC = [[FirstViewController alloc] init];

    SecondViewController *secondVC = [[SecondViewController alloc] init];

    ThirdViewController *thirdVC = [[ThirdViewController alloc] init];

    FouthViewController *fouthVC = [[FouthViewController alloc] init];

    FiveViewController *fiveVC = [[FiveViewController alloc] init];


    //创建导航控制器

    UINavigationController *firstNav = [[UINavigationController alloc] initWithRootViewController:firstVC];

    UINavigationController *secondNav = [[UINavigationController alloc] initWithRootViewController:secondVC];

    UINavigationController *thirdNav = [[UINavigationController alloc] initWithRootViewController:thirdVC];

    UINavigationController *fouthNav = [[UINavigationController alloc] initWithRootViewController:fouthVC];

    UINavigationController *fiveNav = [[UINavigationController alloc] initWithRootViewController:fiveVC];


    //添加标签

    firstNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"推荐" image:[UIImage imageNamed:@"1"] selectedImage:[UIImage imageNamed:@"1"]];

    secondNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"榜单" image:[UIImage imageNamed:@"2"] selectedImage:[UIImage imageNamed:@"2"]];

    thirdNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"分类" image:[UIImage imageNamed:@"3"] selectedImage:[UIImage imageNamed:@"3"]];

    fouthNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"搜索" image:[UIImage imageNamed:@"4"] selectedImage:[UIImage imageNamed:@"4"]];

    fiveNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"应用管理" image:[UIImage imageNamed:@"5"] selectedImage:[UIImage imageNamed:@"5"]];


    //添加到视图控制器上

    self.viewControllers=@[firstNav,secondNav,thirdNav,fouthNav,fiveNav];


    self.selectedViewController = thirdNav;


    self.tabBar.selectedImageTintColor = [UIColor redColor];


    self.tabBar.backgroundColor = [UIColor clearColor];


#import "ThirdViewController.h"

#import "ImageScrollView.h"

@interface ThirdViewController ()

{

    UITableView*table;

    ImageScrollView *banner;

    UIButton*Btn;

}

@end

@implementationThirdViewController

- (void)viewDidLoad {

    [super viewDidLoad];



    self.navigationItem.title = @"分类";

    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];



    table=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];


    table.showsVerticalScrollIndicator = NO;


    table.rowHeight=80;


    table.delegate=self;


    table.dataSource=self;


    [self.view addSubview:table];


    NSArray *arr = @[@"man1.jpg",@"man2.jpg",@"man3.jpg",@"man4.jpg"];




    banner = [[ImageScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 180) style:ImageScrollType_Banner images:arr confirmBtnTitle:nil confirmBtnTitleColor:nil confirmBtnFrame:CGRectZero autoScrollTimeInterval:3 delegate:self];



}

-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{


    return 5;

}

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{


    staticNSString*ID =@"cell";


    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];


    if(!cell) {


        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];


    }


    if(indexPath.row==0) {


        [celladdSubview:banner];


        //添加分页控件


        [banner addPageControlToSuperView:cell];


    }


    else{


    //添加按钮


        Btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];


        Btn.frame=CGRectMake(self.view.frame.size.width-80,25,60,30);


        [Btn setTitle:@"安装" forState:UIControlStateNormal];


        [Btn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];


        Btn.backgroundColor = [UIColor groupTableViewBackgroundColor];


        Btn.layer.borderColor = [UIColor lightGrayColor].CGColor;


        Btn.layer.borderWidth = 1.2;


        [celladdSubview:Btn];



        [Btn addTarget:self action:@selector(bian:) forControlEvents:UIControlEventTouchUpInside];


        cell.textLabel.text=@"青芒阅读";


        cell.detailTextLabel.text = @"学习教育";




    }




    returncell;


}

-(void)bannerImageDidHandleWithIndex:(NSInteger)index{


    NSLog(@"点击了第%ld张图",index+1);


}

-(CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{


    if(indexPath.row==0) {


        return200.0;

    }else

    {

        return80;

    }

}

-(void)bian:(UIButton*)sender{



    [sendersetTitle:@" √ 打开" forState:UIControlStateNormal];


    [sendersetTitleColor:[UIColor redColor] forState:UIControlStateNormal];



}

@end

你可能感兴趣的:(滚动视图 自封装)