custom your cell

本文介绍了两种创建自定义UITableViewCell的方法:一种是通过子类化UITableViewCell并构建每个单元格的自定义视图层级;另一种是覆盖UITableViewCell内容视图的drawRect方法直接在图形上下文中绘制。以iPod应用中的UITableViewCell为例,讲解了如何将自定义的UILabel添加到UITableViewCell中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

There are two primary techniques for creating custom cells. Just likewith our standard UIView subclass, we can either:

     Subclass UITableViewCell and build a custom view hierarchy oneach cell.

     Override the drawRect function of our table view cell’s contentViewand draw on the graphics context directly.


Example
Table View
Using CustomUITableViewCells

Picture, for example, the iPod app’s table view cell. In the left you havea UIImage for the cover art, and in the center you have a UILabel forthe song title. All of these objects rest as a subview to the cell’s view.
In addition to those UI elements, iOS creates an additional blank layerthat you can use to create custom views. Because this blank layer, orcontentView, covers our cell, we can either add subviews or override thedrawRect function

In this code sample, self represents our subclassed UITableViewCell,while myCustomTextLabel is a UILabel that we have created separately. 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值