我如何定製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 selectedBackgroundView定製
- 2. 刪除UITableViewCell定製
- 3. 的UITableViewCell子視圖定製
- 4. 定製uitableviewcell中的導航
- 5. 定製UITableViewCell的高度
- 6. 定製UISwitch一個UITableViewCell
- 7. 返回UITableViewCell定製單元
- 8. 自定義繪製UITableViewCell
- 9. 從NIB擴展定製UITableViewCell
- 10. 定製UITableViewCell與故事板
- 11. 定製UITableViewCell附件未正確定位
- 12. 自定義的UITableViewCell不繪製Corectly
- 13. 我如何定製我的UITableViewCell?
- 14. 定製的UITableViewCell和慢滾動
- 15. 定製UITableViewCell中的NSNotification觀察者?
- 16. UIAppearance沒有造型的定製UITableViewCell
- 17. 繪製一個自定義的UITableViewCell
- 18. 在繪製自定義行的UITableViewCell
- 19. 如何返回無定製的UITableViewCell
- 20. UITableViewCell的定製附件按鈕
- 21. 在定製的UITableViewCell上繪製選定狀態
- 22. UITableView不使用程序定製UITableViewCell
- 23. 用戶界面問題與定製UITableViewCell
- 24. 以編程方式定製UITableViewCell
- 25. 如何製作自定義基本UITableViewCell?
- 26. 無法連接UITableViewCell定製單元IBOutlet
- 27. 定製UITableViewCell不會在setNeedsDisplay上重繪
- 28. 在UITableViewCell中自定義繪製UIView
- 29. 定製uitableviewcell標籤隱藏/顯示
- 30. 定製UITableViewCell和setSelected動畫:動畫: