简体   繁体   中英

Width of a UITableViewCell

I'm creating a UITableView and I need the cells to be of UITableViewCellStyleValue2, that's to say a right-aligned label on the left hand side, like those on the Contacts App.

It works fine but I would like this label to have more width in order to fit the text I want to display.

I haven't find anything on the iOS documentation so is it possible at all? if yes, how? I wonder if I missed something on the search.

Thanks in advance!

I think you need to implement your custom UITableViewCell. Take a look at http://zcentric.com/2008/08/05/custom-uitableviewcell/

as @lluismontero suggests, custom cells give you the most flexibility and are not overly complicated.

if you do want to customize the default cells you can in tableView:cellForRowAtIndexPath: add subviews to the contentView of the default cell after it has been created. You can add any subviews you like so you can add your own right aligned UILabel and don't use the built-in detailTextLabel .

EDIT: remove the suggestion to use 'tableView:willDisplayCell:forRowAtIndexPath:` as the frame is set after this method

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM