Replacement for deprecated sizeWithFont: in iOS 7?

后端 未结 20 984
难免孤独
难免孤独 2020-11-22 08:49

In iOS 7, sizeWithFont: is now deprecated. How do I now pass in the UIFont object into the replacement method sizeWithAttributes:?

20条回答
  •  孤街浪徒
    2020-11-22 09:15

    Alternate solution-

    CGSize expectedLabelSize;
    if ([subTitle respondsToSelector:@selector(sizeWithAttributes:)])
    {
        expectedLabelSize = [subTitle sizeWithAttributes:@{NSFontAttributeName:subTitleLabel.font}];
    }else{
        expectedLabelSize = [subTitle sizeWithFont:subTitleLabel.font constrainedToSize:subTitleLabel.frame.size lineBreakMode:NSLineBreakByWordWrapping];
    }
    

提交回复
热议问题