开发者

TableViewCells width in iPhone

I'm trying to create a cell on a tableview which doesn't go "all the way" from left-to-right of the screen.

Basically, what I need is a cell which (as usual) starts on the left side of the screen, but with a given width, creating a free space on the right.

Is there any way of doing it? I wasn't able to find any example.

Sorry for the eventually noob question, 开发者_如何学运维and many thanks in advance.


In older versions of the SDK this was possible using the initWithFrame:reuseIdentifier:method, however this is deprecated since 3.0, so that you should create the UITableViewCell using the initWithStyle:reuseIdentifier: method.

You can access the frame of the UITableViewCell using the frame property and change it's size:

CGRect frame = cell.frame;
frame.size.width = 123f;
cell.frame = frame;

For indentation on the left side you can simply use the UITableViewDelegate method tableView:indentationLevelForRowAtIndexPath:

You can also add a specific subview to the UITableViewCell on the right side (an accessory view) using the accessoryView property of the cell:

UIView *view = ...
cell.accessoryView = view;

(If the value of this property is not nil, the UITableViewCell class uses the given view for the accessory view in the table view’s normal (default) state; it ignores the value of the accessoryType property. The provided accessory view can be a framework-provided control or label or a custom view. The accessory view appears in the the right side of the cell. UITableViewCell Class Reference)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜