iCarouselDemo_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > iCarouselDemo

iCarouselDemo

 2014/10/22 15:30:25  粉粉色  程序员俱乐部  我要评论(0)
  • 摘要:效果图:项目结构:RootViewController.h#import<UIKit/UIKit.h>#import"iCarousel.h"@interfaceRootViewController:UIViewController<iCarouselDelegate,iCarouselDataSource>{iCarousel*carousel;}@endRootViewController.m#import"RootViewController
  • 标签:

 

效果图:

项目结构:

RootViewController.h

#import <UIKit/UIKit.h>
#import "iCarousel.h"

@interface RootViewController : UIViewController
<iCarouselDelegate,iCarouselDataSource>
{
    iCarousel * carousel;
}
@end

 

RootViewController.m

#import "RootViewController.h"
#import "CardViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)viewDidLoad
{
    [super viewDidLoad];
    
    //背景色
    self.view.backgroundColor = [UIColor colorWithRed:230/255.0 green:192/255.0 blue:203/255.0 alpha:1.0];
    //动画效果
    carousel = [[iCarousel alloc] initWithFrame:CGRectMake(0, 0, 320, 416)];
    carousel.delegate = self;
    carousel.dataSource = self;
    carousel.type = iCarouselTypeCoverFlow;
    [self.view addSubview:carousel];
}
#pragma -mark -iCarouselDelegate
-(NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
    return 36;
}
-(UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index
{
   
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(70, 80, 180, 310)];
    view.backgroundColor = [UIColor yellowColor];
    
    UIImageView * imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.png",index+1]]];
    imageView.frame = CGRectMake(0, 70, 180, 260);
    imageView.backgroundColor = [UIColor yellowColor];
    [view addSubview:imageView];
    
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(40, 10, 100, 30)];
    label.layer.cornerRadius = 10.0;
    label.textAlignment = UITextAlignmentCenter;
    label.backgroundColor = [UIColor lightGrayColor];
    label.text = [NSString stringWithFormat:@"第%d个月",index+1];
    view.layer.cornerRadius = 10.0;
    [view addSubview:label];
    
    
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.backgroundColor = [UIColor clearColor];
    button.tag = index+1;
    button.frame = CGRectMake(0, 0, 180, 310);
    [button addTarget:self action:@selector(choseCard:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:button];
    
    return view;
}

-(void)choseCard:(UIButton *)button
{
    CardViewController * card = [[CardViewController alloc] init] ;
    card.imageName = [NSString stringWithFormat:@"%d.png",button.tag];
    
    if(button.tag<=24){
        card.month = [NSString stringWithFormat:@"第%d个月",button.tag];
        if(button.tag<=12){
            card.title = @"1";
        }
        else{
            card.title = @"2";
        }
    }else if (button.tag == 25 || button.tag == 26 || button.tag == 27){
        card.month = [NSString stringWithFormat:@"第25-27个月"];
        card.title = @"3";
    }else if (button.tag == 28 || button.tag == 29 || button.tag == 30){
        card.month = [NSString stringWithFormat:@"第28-30个月"];
        card.title = @"4";
    }else if (button.tag == 31 || button.tag ==32 || button.tag == 33){
        card.month = [NSString stringWithFormat:@"第31-33个月"];
        card.title = @"5";
    }else if (button.tag == 34 || button.tag == 35 || button.tag == 36){
        card.month = [NSString stringWithFormat:@"第34-36个月"];
        card.title = @"6";
    }
    NSLog(@"%@",card.month);
    [self presentViewController:card animated:YES completion:nil];
}

-(NSUInteger)numberOfPlaceholdersInCarousel:(iCarousel *)carousel
{
    return 0;
}
-(NSUInteger)numberOfVisibleItemsInCarousel:(iCarousel *)carousel
{
    return 30;
}
-(CGFloat)carouselItemWidth:(iCarousel *)carousel
{
    return 200;
}
-(BOOL)carouselShouldWrap:(iCarousel *)carousel
{
    return YES;
}

@end

 

myCell.h

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface myCell : UITableViewCell
{
    UILabel * myLable;
    UIImageView * myImageView;
    UILabel * title;
}
@property (strong,nonatomic) UILabel * myLabel;
@property (strong,nonatomic) UIImageView * myImageView;
@property (strong,nonatomic) UILabel * title;
@end

 

myCell.m

#import "myCell.h"

@implementation myCell

@synthesize myLabel;
@synthesize myImageView;
@synthesize title;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        myLabel = [[UILabel alloc] init];
        myLabel.lineBreakMode=NSLineBreakByCharWrapping;
        myLabel.numberOfLines = 0;
        myLabel.font = [UIFont fontWithName:@"MicrosoftYaHei" size:20.0];
        [self addSubview:myLabel];
        
        myImageView = [[UIImageView alloc] init];
        [self addSubview:myImageView];
        
        title = [[UILabel alloc] init];
        title.frame = CGRectMake(10, 10, 50, 30);
        title.backgroundColor = [UIColor colorWithRed:230/255.0 green:192/255.0 blue:203/255.0 alpha:1.0];
        title.layer.cornerRadius = 10.0;
        [self addSubview:title];
       ;
    }
    return self;
}

 

CardViewController.h

#import <UIKit/UIKit.h>

@interface CardViewController : UIViewController
<UITableViewDataSource,UITableViewDelegate>
{
    NSMutableArray *array ;
    NSMutableArray * titleArray;
}
@property (strong ,nonatomic) NSMutableArray *array;
@property (strong,nonatomic) NSString * month;
@property (strong,nonatomic) NSString * imageName;
@property (strong,nonatomic) NSString *title;

@end

 

CardViewController.m

#import "CardViewController.h"
#import "myCell.h"

@interface CardViewController ()

@end

@implementation CardViewController
@synthesize array;
@synthesize month;
@synthesize imageName;
@synthesize title;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)viewDidLoad
{
    [super viewDidLoad];
    
    
    NSDictionary * dic1 = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"BabyCard" ofType:@"plist"]];
    self.array = [dic1 objectForKey:month];
    
    NSDictionary * dic2 = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Title" ofType:@"plist"]];
    titleArray = [[NSMutableArray alloc] init];
    titleArray = [dic2 objectForKey:title];
    
    UITableView * tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460) style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:tableView];
    
    
    UIButton * back = [UIButton buttonWithType:UIButtonTypeCustom];
    back.frame = CGRectMake(10, 10, 25, 31);
    [back setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    [back addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [tableView addSubview:back];
}
#pragma -mark -doClickActions
-(void)back
{
    CATransition *animation = [CATransition animation];
    animation.delegate = self;
    animation.duration = 0.7;
    animation.type = @"oglFlip";
    animation.subtype = kCATransitionFromLeft;
    [self.view.layer addAnimation:animation forKey:@"animation"];
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
#pragma -mark -UITableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return array.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString * str = [array objectAtIndex:indexPath.row];
  
    CGSize size=[str boundingRectWithSize:CGSizeMake(300, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:20.0]} context:nil].size;

    
    if(indexPath.row == 0)
    {
         return size.height + 350;
    }
    else
    {
        return size.height + 60;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    myCell * cell = [tableView dequeueReusableCellWithIdentifier:@"id"];
    if(cell == nil){
        cell = [[myCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"id"];
    }
    
    NSString * str = [array objectAtIndex:indexPath.row];
    CGSize size=[str boundingRectWithSize:CGSizeMake(300, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:20.0]} context:nil].size;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
   
    NSString * str2 = [NSString stringWithFormat:@" %@ ",[titleArray objectAtIndex:indexPath.row]];
    CGSize size2=[str boundingRectWithSize:CGSizeMake(300, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:10.0]} context:nil].size;
    cell.title.text = str2;
    if(indexPath.row == 0){
        cell.myImageView.hidden = NO;
        cell.myImageView.image = [UIImage imageNamed:imageName];
        cell.myImageView.frame = CGRectMake(0, 0, 320, 300);
        cell.myLabel.frame = CGRectMake(10, 350, 300, size.height);
        cell.title.frame = CGRectMake(10, 310, size2.width, 30);
    }else{
        cell.myImageView.hidden = YES;
        cell.myLabel.frame = CGRectMake(10, 50, 300, size.height);
        cell.title.frame = CGRectMake(10, 10,size2.width, 30);
    }
    cell.myLabel.text = str;
    return cell;
}
@end

 

  • 相关文章
发表评论
用户名: 匿名