2

In iOS 7 some of the most important string drawing and metrics calculation methods were depracated with no obvious alternative given.

enter image description here

The page on NSString UIKit Additions Reference is red like blood. Almost everything deprecated. Xcode throws 300 warnings at me.

I try to find out what was running through Apples mind and what they changed in UIKit text system but where would I start? Did they mention somewhere why all of this is deprecated and how the text system works different now? And how to adapt? How to calculate text bounding box when label can scale the font to fit size? Is TextKit the solution?

I spent 3 hours on Google but I found no useful information on how to solve this problem.

We should document all alternatives here so all developers who run into this depressive deprecation mess find peace of mind quickly.

openfrog
  • 40,201
  • 65
  • 225
  • 373

1 Answers1

1

If you look at the deprecations, most of them deprecate the use of UIFont to use a dictionary of attributes instead.

drawInRect:withFont: (Deprecated in iOS 7.0. Use drawInRect:withAttributes: instead.) drawInRect:withFont:lineBreakMode: (Deprecated in iOS 7.0. Use drawInRect:withAttributes: instead.)
sizeWithFont:(Deprecated in iOS 7.0. Use sizeWithAttributes: instead.) etc…

So if you're looking for a place to start, learn how to use dictionaries of attributes to set up fonts. It looks like a lot of deprecations, but you don't actually need to learn that much new stuff.

If you want to update your code to use the new TextKit system, check out the WWDC videos and the TextKit Programming Guide.

If you want to know Apple's reason for deprecating so much, I'd guess that it has to do with how UILabel and UITextView used to be built on web views, now they're built on TextKit.

nevan king
  • 112,709
  • 45
  • 203
  • 241
  • Thank you Nevan. Do you know if it is still possible to calculate actual font size? I couldn't find a solution for this one (http://stackoverflow.com/questions/19195541/how-to-calculate-actual-font-size-in-ios-7) – openfrog Oct 05 '13 at 10:57
  • Did you try using the linked question in that post. The post is marked as a duplicate to a question with an answer. – nevan king Oct 05 '13 at 10:59
  • Yes, and as my edit states this is wrong. The linked question is not at all related to the problem of calculating actual font size. It deals with calculating the text rectangle and nothing more. Or did I miss the hint in there? – openfrog Oct 05 '13 at 11:03
  • Sorry, I don't know enough about the specifics to answer it. It looks like Apple is suggesting that you don't change the font size. I'd suggest that you just continue to use the deprecated method, turn off warnings for that specific case, and update to the new system at a later date. – nevan king Oct 05 '13 at 11:26