我如何定制UITableviewCell,因为我想在单个单元中看到标签,日期和图片。定制的UITableViewCell
3
A
回答
1
看一看这个链接定制的UITableViewCell。
在那里您会找到如何使用Interface Builder制作自定义单元格,并在XCode中将它用于您的应用程序。
http://www.e-string.com/content/custom-uitableviewcells-interface-builder
3
有两种选择(可能会更多)。您可以使用本机UITableViewCell属性将内容添加到单元格,或创建一个自定义单元格(我的意思是,将您自己的子视图添加到单元格中)。要开始尝试第一个,它简单优雅,结果会相当不错。例如试试下面的单元格创建方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// notice the Style. The UITableViewCell has a few very good styles that make your cells look very good with little effort
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
// In my case I get the data from the elements array that has a bunch on dictionaries
NSDictionary *d = [elements objectAtIndex:indexPath.row];
// the textLabel is the main label
cell.textLabel.text = [d objectForKey:@"title"];
// the detailTextLabel is the subtitle
cell.detailTextLabel.text = [d objectForKey:@"date"];
// Set the image on the cell. In this case I load an image from the bundle
cell.imageView.image = [UIImage imageNamed:@"fsaint.png"];
return cell;
}
2
您可以使用Interface Builder或通过Code
0
我重写的UITableViewCell类,并做风俗画self.contentView的忠实粉丝。这种技术稍微复杂一些,但它会带来更好的滚动性能。
例如,假设你重写你的细胞,并有3个属性就可以了,像这样:
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
[userPic drawInRect: CGRectMake(10, 5, 50, 50)];
[label drawAtPoint:CGPointMake(70, 5) withFont:[UIFont boldSystemFontOfSize:17]];
[date drawAtPoint:CGPointMake(70, 30) withFont:[UIFont systemFontOfSize:14]];
}
:
@property(nonatomic, retain) UIImage *userPic;
@property(nonatomic, retain) NSString *label;
@property(nonatomic, retain) NSString *date;
然后你可以使用(drawRect中:)功能吸引他们在细胞
欲了解更多示例,请查看此框架使用此款式:https://github.com/andrewzimmer906/XCell
相关问题
- 1. 定制uitableviewcell中的导航
- 2. 自定义绘制UITableViewCell
- 3. 从NIB扩展定制UITableViewCell
- 4. 返回UITableViewCell定制单元
- 5. 定制UITableViewCell附件未正确定位
- 6. 如何返回无定制的UITableViewCell
- 7. UIAppearance没有造型的定制UITableViewCell
- 8. 在绘制自定义行的UITableViewCell
- 9. 定制的UITableViewCell和慢滚动
- 10. 我如何定制我的UITableViewCell?
- 11. 在定制的UITableViewCell上绘制选定状态
- 12. 如何制作自定义基本UITableViewCell?
- 13. 定制UITableViewCell和setSelected动画:动画:
- 14. UITableViewCell自定义重新排序控制
- 15. 定制UITableViewCell不会在setNeedsDisplay上重绘
- 16. 从UITableViewController继承的控制器中定制uitableViewCell
- 17. 绘制阴影的UITableViewCell
- 18. UITableViewCell自定义
- 19. 自定义UITableViewCell
- 20. UITableViewCell自定义
- 21. 自定义UITableViewCell
- 22. 自定义UITableViewCell
- 23. 定制和自定义删除按钮为自定义UITableViewCell
- 24. 确定UITableViewCell中的UIButton
- 25. 自定义的UITableViewCell + resignFirstResponder
- 26. 自定单元的UITableViewCell
- 27. 固定高度的UITableViewCell
- 28. UITableViewCell的定式编程
- 29. 自定义的UITableViewCell消失
- 30. 自定义的UITableViewCell NSUnknownKeyException