Kahsn
Kahsn

Reputation: 1045

Converting sizeWithFont method to Swift

I'm going over old obj-c tutorial and having hard time understanding obj-c code. And they are apparantely deprecated. I've looked into other stackoverflow questions but I still could not figure out since none of them were not in Swift.

   CGSize textSize = [text sizeWithFont:textFont constrainedToSize:CGSizeMake(printableFrame.size.width, CGFLOAT_MAX) lineBreakMode:UILineBreakModeWordWrap];
   CGRect textFrame = CGRectMake(printableFrame.origin.x, currentY, textSize.width, textSize.height);

How can I convert above code to Swift?

Upvotes: 4

Views: 12386

Answers (1)

XmasRights
XmasRights

Reputation: 1509

The method was deprecated in favour of sizeWithAttributes.

Replacement for deprecated sizeWithFont: in iOS 7?

To convert to swift, unfortunately it looks like you'll have to have to use an NSString in your code

CGSize sizeWithAttributes in Swift

Clean, but this will impact performance, so you may want to find another solution if these lines are called a lot.

Upvotes: 6

Related Questions