0

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

Community
  • 1
  • 1
  • 1
    `heightForRowAtIndexPath` is the best choice AFAIK. – Akshit Zaveri Jan 04 '15 at 06:55
  • Can you show some code please? –  Jan 04 '15 at 06:56
  • 1
    @MikeSteevson code is not necessary as its not a coding question its an off topic question. Regardless Mike, If your deployment target is iOS8 apple has implemented something called UITableViewAutomaticDimension that takes care of all of this. If your subclassing cells it's a different story, don't forget auto layout constraints should be taken into consideration as well. Furthermore, this is a forum for helping OPs resolve coding issues, if you just need how-to-guides or tutorials just do a quick google search before asking. There are numerous tutorials on this subject, especially in Obj C – soulshined Jan 04 '15 at 07:03
  • @soulshined is right, and about the code, you can see numerous answers in the link that you have included in your question. – Akshit Zaveri Jan 04 '15 at 07:04
  • If you have a label or something which is not default, you will need to take those parameters into considerations while you calculate your cell's height. Otherwise you can just do it without any font parameter or anything else. – Akshit Zaveri Jan 04 '15 at 07:06
  • what exactly you have in cell? please let us know details for the same... – Fahim Parkar Jan 04 '15 at 07:39
  • You've got two separate tasks: 1) Determine how tall the cell should be, and 2) size the cell appropriately. Which are you having trouble with? – Hot Licks Jan 04 '15 at 14:41
  • determining how tall it should be –  Jan 04 '15 at 17:02
  • if you are using autolayout, this tutorial is awesome http://www.raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout – Nik Yekimov Jan 05 '15 at 04:16

1 Answers1

0

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...

Community
  • 1
  • 1
stevesliva
  • 5,351
  • 1
  • 16
  • 39