博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【代码笔记】iOS-iCarouselDemo
阅读量:4553 次
发布时间:2019-06-08

本文共 5898 字,大约阅读时间需要 19 分钟。

一,效果图。

二,工程图。

三,代码。

RootViewController.h

RootViewController.m

myCell.h

#import 
#import
@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;}- (void)setSelected:(BOOL)selected animated:(BOOL)animated{    [super setSelected:selected animated:animated];    // Configure the view for the selected state}@end

 

CardViewController.h

#import 
@interface CardViewController : UIViewController
{ 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

转载于:https://www.cnblogs.com/yang-guang-girl/p/5429702.html

你可能感兴趣的文章
python高效读取文件、文件改写
查看>>
gulp
查看>>
pgsql查询优化之模糊查询
查看>>
[转]-Gradle使用手册(三):构建任务
查看>>
ExtJS下拉树
查看>>
android 调用系统相机录像并保存
查看>>
BW系统表的命名规则
查看>>
Asp.Net在IE10下出现_doPostBack未定义的解决办法 LinkButton
查看>>
《CLR via C#》Part2之Chapter5 基元类型、引用类型和值类型(一)
查看>>
1-9 RHEL7-文件权限管理
查看>>
apache服务器安装
查看>>
Search a 2D Matrix
查看>>
文件解析漏洞
查看>>
弹性成像的一些术语
查看>>
作业2
查看>>
vim 笔记
查看>>
MySQL的基本使用命令
查看>>
output 参数在存储过程中的用法
查看>>
大数加法和乘法(高精度)
查看>>
利用SynchronizationContext.Current在线程间同步上下文
查看>>