通讯录图库界面,两种cell的定制
来源:互联网 发布:在哪里下载软件 编辑:程序博客网 时间:2024/05/23 11:28
@interface FYZMalePersonCell : UITableViewCell@property (nonatomic, retain) PhotoInfo *photoInfo;//接收c传入的M<span style="background-color: rgb(153, 153, 255);">//动态设置cell的高度+ (CGFloat)heightForRowWithModel:(PhotoInfo *)photoInfo;</span>@end<pre name="code" class="objc">@interface FYZMalePersonCell ()@property (nonatomic, retain) UIImageView *iconView; //显示图标@property (nonatomic, retain) UILabel *titleLabel; //显示名字与职称@property (nonatomic, retain) UILabel *descriptionLabel; //显示图片描述@property (nonatomic, retain) UIImageView *photoView; //显示图片@end@implementation FYZMalePersonCell//重写setter- (void)setPhotoInfo:(PhotoInfo *)photoInfo{ if (_photoInfo != photoInfo) { [_photoInfo release]; _photoInfo = [photoInfo retain]; } //为自身控件赋值 //(1)图标 self.iconView.image = [UIImage imageNamed:@"lanou"]; //(2)名字加职称 self.titleLabel.text = [NSString stringWithFormat:@"%@, %@", photoInfo.name, photoInfo.title]; //(3)简介 //修改descriptionLabel的高度 CGRect desFrame = _descriptionLabel.frame; desFrame.size.height = [[self class] heightForText:photoInfo.introduction];//[self class]获取当前类 _descriptionLabel.frame = desFrame; self.descriptionLabel.text = photoInfo.introduction; //(4)图片 //修改photoView高度 CGRect photoFrame = _photoView.frame; photoFrame.origin.y = desFrame.size.height + desFrame.origin.y; UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FYZ" ofType:@"png"]]; photoFrame.size.height = [[self class] heightForImage:image]; _photoView.frame = photoFrame; self.photoView.image = image; }- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { // Initialization code //iconView CGFloat px = kPhotoCell_MarginLeft; CGFloat py = kPhotoCell_MarginBetween; CGFloat width = kPhotoCell_IconView_Width; CGFloat height = kPhotoCell_IconView_Height; self.iconView = [[UIImageView alloc] initWithFrame:CGRectMake(px, py, width, height)]; [self.contentView addSubview:_iconView]; [_iconView release]; //titleLabel px = px + width + kPhotoCell_MarginLeft; py = py; width = kPhotoCell_TitleLabel_Width; height = kPhotoCell_TitleLabel_Height; self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(px, py, width, height)]; _titleLabel.font = [UIFont systemFontOfSize:kFont_Size]; _titleLabel.textColor = [UIColor lightGrayColor]; [self.contentView addSubview:_titleLabel]; [_titleLabel release]; //descriptionLabel px = kPhotoCell_MarginLeft; py = py + height + kPhotoCell_MarginBetween; width = kPhotoCell_Width; height = 0; self.descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(px, py, width, height)]; _descriptionLabel.numberOfLines = 0; _descriptionLabel.font = [UIFont systemFontOfSize:kFont_Size]; [self.contentView addSubview:_descriptionLabel]; [_descriptionLabel release]; //photoView px = px; py = py + height + kPhotoCell_MarginBetween; width = kPhotoCell_Width; height = 0; self.photoView = [[UIImageView alloc] initWithFrame:CGRectMake(px, py, width, height)]; [self.contentView addSubview:_photoView]; [_photoView release]; } return self;}- (void)awakeFromNib{ // Initialization code}- (void)setSelected:(BOOL)selected animated:(BOOL)animated{ [super setSelected:selected animated:animated]; // Configure the view for the selected state}<span style="background-color: rgb(153, 153, 255);">+ (CGFloat)heightForRowWithModel:(PhotoInfo *)photoInfo{ //1.图片高度</span> //让图片等比例缩放(防止图片失真) //(1)获取图片 UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FYZ" ofType:@"png"]]; CGFloat imageHeight = [self heightForImage:image]; //2.文本的高度 CGFloat textHeight = [self heightForText:photoInfo.introduction]; //3.返回cell的总高度 return kPhotoCell_TitleLabel_Height + imageHeight + textHeight + 3 * kPhotoCell_MarginBetween;}//单独计算图片的高度<span style="background-color: rgb(153, 153, 255);">+ (CGFloat)heightForImage:(UIImage *)image{</span> //(2)获取图片的大小 CGSize size = image.size; //(3)求出缩放比例 CGFloat scale = kPhotoCell_Width / size.width; CGFloat imageHeight = size.height * scale; return imageHeight;}<span style="background-color: rgb(153, 153, 255);">//单独计算文本的高度+ (CGFloat)heightForText:(NSString *)text{</span> //2.文本的高度 //设置计算文本时,字体的大小,以什么标准来计算 //第一个参数:限制范围 2个:设置文本高和间距 3个:字体的大小 NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:kFont_Size]}; CGSize textSize = [text boundingRectWithSize:CGSizeMake(kPhotoCell_Width, 1000) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size; return textSize.height;}- (void)dealloc{ RELEASE_SAFE(_descriptionLabel); RELEASE_SAFE(_iconView); RELEASE_SAFE(_titleLabel); RELEASE_SAFE(_photoView); RELEASE_SAFE(_photoInfo); [super dealloc];}@endfemale cell
@interface FYZFemalePersonCell : UITableViewCell@property (nonatomic, retain) PhotoInfo *photoInfo;<span style="background-color: rgb(153, 153, 255);">//动态设置cell的高度+ (CGFloat)heightForRowWithModel:(PhotoInfo *)photoInfo;@end</span>
@interface FYZFemalePersonCell ()@property (nonatomic, retain) UIImageView *iconView; //显示图标@property (nonatomic, retain) UILabel *titleLabel; //显示名字与职称@property (nonatomic, retain) UILabel *descriptionLabel; //显示图片描述@property (nonatomic, retain) UIImageView *photoView; //显示图片@end@implementation FYZFemalePersonCell//重写setter方法为控件赋值- (void)setPhotoInfo:(PhotoInfo *)photoInfo{ if (_photoInfo != photoInfo) { [_photoInfo release]; _photoInfo = [photoInfo retain]; } //赋值 //(1)图标 self.iconView.image = [UIImage imageNamed:@"lanou"]; //(2)titleLabel self.titleLabel.text = [NSString stringWithFormat:@"%@, %@", photoInfo.name, photoInfo.title]; //(3)图片 //修改photoView高度 CGRect photoFrame = _photoView.frame; UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FYZ" ofType:@"png"]]; photoFrame.size.height = [[self class] heightForImage:image]; //_photoView.frame = photoFrame; self.photoView.image = image; //(4)简介 //修改descriptionLabel的高度 CGRect desFrame = _descriptionLabel.frame; desFrame.size.height = [[self class] heightForText:photoInfo.introduction];//[self class]获取当前类 desFrame.origin.y = photoFrame.size.height + photoFrame.origin.y; _descriptionLabel.frame = desFrame; self.descriptionLabel.text = photoInfo.introduction; }- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { // Initialization code //titleLabel CGFloat px = kPhotoCell_MarginLeft; CGFloat py = kPhotoCell_MarginBetween; CGFloat width = kPhotoCell_TitleLabel_Width; CGFloat height = kPhotoCell_TitleLabel_Height; self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(px, py, width, height)]; [self.contentView addSubview:_titleLabel]; [_titleLabel release]; //iconView px = px + width + kPhotoCell_MarginLeft; py = py; width = kPhotoCell_IconView_Width; height = kPhotoCell_IconView_Height; self.iconView = [[UIImageView alloc] initWithFrame:CGRectMake(px, py, width, height)]; [self.contentView addSubview:_iconView]; [_iconView release]; //descriptionLabel px = kPhotoCell_MarginLeft; py = py + height + kPhotoCell_MarginBetween; width = kPhotoCell_Width; height = 0; self.photoView = [[UIImageView alloc] initWithFrame:CGRectMake(px, py, width, height)]; [self.contentView addSubview:_photoView]; [_photoView release]; //photoView px = px; py = py + height; width = kPhotoCell_Width; height = 0; self.descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(px, py, width, height)]; _descriptionLabel.font = [UIFont systemFontOfSize:kFont_Size]; _descriptionLabel.numberOfLines = 0; [self.contentView addSubview:_descriptionLabel]; [_descriptionLabel release]; } return self;}+ (CGFloat)heightForRowWithModel:(PhotoInfo *)photoInfo{ //1.图片高度 //让图片等比例缩放(防止图片失真) //(1)获取图片 UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FYZ" ofType:@"png"]]; CGFloat imageHeight = [self heightForImage:image]; //2.文本的高度 CGFloat textHeight = [self heightForText:photoInfo.introduction]; //3.返回cell的总高度 return kPhotoCell_TitleLabel_Height + imageHeight + textHeight + 3 * kPhotoCell_MarginBetween;}//单独计算图片的高度+ (CGFloat)heightForImage:(UIImage *)image{ //(2)获取图片的大小 CGSize size = image.size; //(3)求出缩放比例 CGFloat scale = kPhotoCell_Width / size.width; CGFloat imageHeight = size.height * scale; return imageHeight;}//单独计算文本的高度+ (CGFloat)heightForText:(NSString *)text{ //2.文本的高度 //设置计算文本时,字体的大小,以什么标准来计算 //第一个参数:限制范围 2个:设置文本高和间距 3个:字体的大小 NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:kFont_Size]}; CGSize textSize = [text boundingRectWithSize:CGSizeMake(kPhotoCell_Width, 1000) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size; return textSize.height;}- (void)awakeFromNib{ // Initialization code}- (void)setSelected:(BOOL)selected animated:(BOOL)animated{ [super setSelected:selected animated:animated]; // Configure the view for the selected state}- (void)dealloc{ RELEASE_SAFE(_descriptionLabel); RELEASE_SAFE(_iconView); RELEASE_SAFE(_titleLabel); RELEASE_SAFE(_photoView); [super dealloc];}@end
@interface <span style="background-color: rgb(153, 153, 255);">FYZPhotoPersonHelper</span> : NSObject+ (FYZPhotoPersonHelper *)sharedPhotoPersonHelper;//分区数+ (NSInteger)numberOfSections;//分区元素+ (NSInteger) numberOfRowsInSection:(NSInteger)section;//返回photoInfo对象+ (PhotoInfo *)photoInfoAtIndexPath:(NSIndexPath *)indexPath;@end
@interface FYZPhotoPersonHelper ()@property (nonatomic, retain) NSMutableArray *photoArr;@end@implementation FYZPhotoPersonHelperstatic FYZPhotoPersonHelper *helper = nil;+ (FYZPhotoPersonHelper *)sharedPhotoPersonHelper{ @synchronized(self) { if (!helper) { helper = [[FYZPhotoPersonHelper alloc] init]; [helper readDataFromPlist]; } } return helper;}- (void<span style="background-color: rgb(153, 153, 255);">)readDataFromPlist</span>{ //获取路径 NSString *filePath = [[NSBundle mainBundle] pathForResource:@"PresonList" ofType:@"plist"]; //根据路径初始化数组对象 NSArray *arr = [NSArray arrayWithContentsOfFile:filePath]; //创建可变数组,存储封装好的photoInfo对象 self.photoArr = [NSMutableArray array]; //遍历数组,将小子点封装成photoInfo对象 for (NSDictionary *tempDic in arr) { PhotoInfo *photo = [[PhotoInfo alloc] initWithDic:tempDic]; [_photoArr addObject:photo]; RELEASE_SAFE(photo); }}+ (NSInteger)numberOfSections{ //先调用这个方法创建helper [FYZPhotoPersonHelper sharedPhotoPersonHelper]; return 1;}+ (NSInteger) numberOfRowsInSection:(NSInteger)section{ return helper.photoArr.count;}+ (PhotoInfo *)photoInfoAtIndexPath:(NSIndexPath *)indexPath{ return helper.photoArr[indexPath.row];}@end
0 0
- 通讯录图库界面,两种cell的定制
- cell的定制界面
- iOS Cell 的高级定制
- 一个UITableView两种Cell的实现
- 定制cell
- 定制ListView的界面
- android的界面定制
- 定制ListView的界面
- 定制ListView的界面
- Ueditor的两种定制方式
- 系统通讯录界面的使用
- 代码实现Cell的自定制
- 定制化的Cell, 如何获得NSIndexPath
- 聊天界面cell的搭建
- iOS 获取系统通讯录的两种方法
- iOS 获取手机通讯录常用的两种方式
- UITableView的cell的两种动画效果。
- UITableView的两种重用Cell方法的区别
- nyoj28大数阶乘
- 线程同步控制的几种方式
- 阿里巴巴之孕育、裂变及归因
- dll加载问题的解决方法
- 腾讯2014实习生招聘经历谈
- 通讯录图库界面,两种cell的定制
- 在控制台中动态引入jquery的方法
- C++ Map快速入门
- IOS 6 自动布局 入门-1
- Perl、PHP、Python、Java和Ruby的比较
- 平台商业模式成就了阿里巴巴
- 网页基础第1课之“ 利用 session 实现循环3次登录验证”
- Eclipse衍生版本之ADT Bundle
- 腾讯2014年实习生招聘笔试面试经历