Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
641 views
in Technique[技术] by (71.8m points)

ios7 - IOS 7 sizeWithFont Deprecated

I cannot seem to replace the deprecated sizeWithFont with boundingRecWithSize correctly. I scoured through all the answers and stayed up all night trying to fix this.I really need help from someone way smarter than I. Here is the code I am trying to modify. Any help would be appreciated.

CGSize sizeForText = [faqItem.answer sizeWithFont:[UIFont boldSystemFontOfSize:14]
   constrainedToSize:CGSizeMake(self.tblView.bounds.size.width - padding, MAXFLOAT)
   lineBreakMode:NSLineBreakByWordWrapping];

[sectionInfo insertObject:[NSNumber numberWithFloat:roundf(sizeForText.height + 5)]
  inRowHeightsAtIndex:0];
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to use the sizeWithAttributes property.

CGSize mysize = [string sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14.0f]}];

You can also set it to an already created font size in order to reduce recoding if you use the size more than once:

CGSize mysize = [string sizeWithAttributes:@{NSFontAttributeName: label1.font}];

I do not believe you can use constrainedToSize with this property. It would have to be separately set on a CGRect.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...