ICarouselDemo, icarousel

Source: Internet
Author: User

ICarouselDemo, icarousel

 

:

Project Structure:

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 *) bundle :( NSBundle *) handle {self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// Custom initialization} return self;}-(void) viewDidLoad {[super viewDidLoad]; // background color self. view. backgroundColor = [UIColor colorwithred: 230/255. 0 green: 192/255. 0 blue: 203/255. 0 alpha: 1.0]; // animated effect movie usel = [[iCarousel alloc] initWithFrame: CGRectMake (0, 0,320,416)]; movie usel. delegate = self; invalid usel. dataSource = self; usel. type = iCarouselTypeCoverFlow; [self. view addSubview: carousel];} # pragma-mark-iCarouselDelegate-(NSUInteger) Restart :( 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: @ "mongod.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: @ "month % 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: @ "mongod.png", button. tag]; if (button. tag <= 24) {card. month = [NSString stringWithFormat: @ "month % 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-25- "]; card. title = @ "3";} else if (button. tag = 28 | button. tag = 29 | button. tag = 30) {card. month = [NSString stringWithFormat: @ "month 28-30"]; card. title = @ "4";} else if (button. tag = 31 | button. tag = 32 | button. tag = 33) {card. month = [NSString stringWithFormat: @ "month 31-33"]; card. title = @ "5";} else if (button. tag = 34 | button. tag = 35 | button. tag = 36) {card. month = [NSString stringWithFormat: @ "month 34-36"]; card. title = @ "6";} NSLog (@ "% @", card. month); [self presentViewController: card animated: YES completion: nil];}-(NSUInteger) numberOfPlaceholdersInCarousel :( iCarousel *) incluusel {return 0;}-(NSUInteger) usage :( iCarousel *) specify usel {return 30;}-(CGFloat) specify uselitemwidth :( iCarousel *) specify usel {return 200;}-(BOOL) specify uselshouldwrap :( 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

 




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.