自定义Cell与动态确定Cell高…
来源:互联网 发布:烙印战士 漫画软件 编辑:程序博客网 时间:2024/06/01 10:41
#import"DiseaseListCell.h"
@implementation DiseaseListCell
@synthesize titleLabel;
@synthesize cellBackgroundImage;
-(id)initWithStyle:(UITableViewCellStyle)stylereuseIdentifier:(NSString *)reuseIdentifier {
titleLabel.highlightedTextColor = [UIColor blackColor];
cellBackgroundImage = [[UIImageView alloc] init];
}
-(void)setSelected:(BOOL)selected animated:(BOOL)animated {
//我自定义的cell在点击的时候没显示选中的效果,应该是在这里需要进行设置
}
-(void)layoutSubviews
{
[superlayoutSubviews];
cellBackgroundImage.frame = CGRectMake(0, 0, 320, 44);
cellBackgroundImage.backgroundColor = [UIColor clearColor];
cellBackgroundImage.image = [UIImageimageNamed:@"DiseaseListCell.png"];
[self.contentView addSubview:cellBackgroundImage];
titleLabel.frame = CGRectMake(15, 5, 260.0, 30);
titleLabel.font= [UIFont systemFontOfSize:22];
titleLabel.textAlignment = UITextAlignmentLeft;
titleLabel.textColor =
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.lineBreakMode = UILineBreakModeWordWrap;
[self.contentView addSubview:titleLabel];
}
- (void)dealloc {
[titleLabel release];
[cellBackgroundImage release];
}
@end
//在viewController中用到自定义cell时,在方法中如下声明引入
-(UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath {
//....接下来就是给cell中各个元素赋值了
//....
}
selectedRow= 0;
//selectedRow用于判断cell是否应该进行扩展,初始化为0可以使初始化时第一行扩展显示,如果开始时都不需要扩展,可以设为-1
//heightForRowAtIndexPath这个方法在cellForRowAtIndexPath之前运行
- (CGFloat) tableView:(UITableView *)tableViewheightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row != selectedRow) return CellHeight;//CellHeight是预定义的内容
else{
//这里进行cell内容的获取,并且计算高度
NSString *infoString= [[diseaseDetailArray objectAtIndex:indexPath.row]objectForKey:@"info"];
CGSize constraint =CGSizeMake(280, 20000);
CGSize size =[infoString sizeWithFont:[UIFontsystemFontOfSize:16]
constrainedToSize:constraintlineBreakMode:UILineBreakModeWordWrap];
CGFloat height =MAX(size.height, CellHeight);
return height + (5 *2) + CellHeight;
}
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath {
//...
//...加载cell内容
//...
if (indexPath.row != selectedRow){
detailCell.cellBackgroundImage.frame = CGRectMake(0, 0,MainWindowWidth, CellHeight);
detailCell.cellBackgroundImage.image = [UIImageimageNamed:@"DiseaseDetailCell.png"];
detailCell.infoLabel.text = nil;
}
else {
//与上面确定高度时类似
NSString *infoString= [[diseaseDetailArray objectAtIndex:indexPath.row]objectForKey:@"info"];
CGSize constraint =CGSizeMake(280, 20000);
CGSize size =[infoString sizeWithFont:[UIFontsystemFontOfSize:16]
constrainedToSize:constraintlineBreakMode:UILineBreakModeWordWrap];
[detailCell.infoLabel setText:infoString];
[detailCell.infoLabel setFrame:CGRectMake(20, 44, 280,MAX(size.height, 44))];
detailCell.cellBackgroundImage.frame = CGRectMake(0, 0,MainWindowWidth, MAX(size.height, 44) + 54);
detailCell.cellBackgroundImage.image = [UIImageimageNamed:@"DetailViewBng.png"];
//==============================================================================================
return detailCell;
}
- 自定义Cell与动态确定Cell高…
- 自定义Cell行高
- 自定义不等高的cell
- 自定义等高的cell
- 自定义不等高的cell
- iOS 自定义等高cell
- 自定义等高的cell
- 【iOS】UITableView 动态确定cell的高度
- iOS中最简单实用的自定义动态返回行高的cell,动态计算cell的高度
- IOS开发-15.自定义cell(等高cell)
- Cell自定义registerNib:与registerClass:
- UIWebView与动态创建Cell
- 自定义cell
- 自定义cell
- 自定义cell
- 自定义cell
- 自定义cell
- 自定义cell
- TableView详细解释
- iOS动画
- UIToolBar 三种办法(转)
- ios开发知识点
- iPhone的Socket编程使用开源代码之…
- 自定义Cell与动态确定Cell高…
- UIApplicationDelegate
- OS X 10.8 Mountain Lion GM…
- iphone之Prefix.pch的作用和…
- IOS 手势识别教程:二指拨动…
- 申请开发或发布证书 xcode4.4
- 二维码扫瞄 ZXingWidge…
- ios实现程序切入后台,实现后台任…
- 常用RGB颜色表 色值