简体   繁体   中英

Size UITableViewCell to fit to content

I'm kinda new to objective c, so please don't be too harsh on me if it's a stupid question. I want to size a UITableViewCell to fit to it's content. I did a search and found this and it makes you insert a font size. I don't wanna do that, I want the cell to just check what the size it needs to be, then size it accordingly.

Thanks

Use [UIFont labelFontSize] with the answer you cite. It gives you the default font size of the text in the UILabel in the UITableViewCell. I don't see any reason to use another solution. Your problem is finding the default font size. Because if you weren't using the default, you'd know the font size.

The Dec '14 answer at the bottom looks good too.

FWIW, I just answer this sort of thing by clicking through the Apple Class Reference docs. Oh, the cell has a UILabel. UILabel has a font property. UIFont has a class method called labelFontSize, so if I have a label, and I haven't specified a font size...

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