stringSize = [string boundingRectWithSize:CGSizeMake(200,300) options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:@{NSFontAttributeName:[UIFont fontWithName:self.stringLabel.font.fontName size:self.stringLabel.font.pointSize]} context:nil];
原始代码是
stringSize = [string sizeWithFont:self.stringLabel.font constrainedToSize:CGSizeMake(200, 300)];
但Apple的Xcode表示它已被弃用,因此我想更新它,现在我遇到了第一个参数的问题。
我收到一条错误,上面写着以下内容
SVProgressHUD.m:298:28: Assigning to 'CGSize' (aka 'struct CGSize') from incompatible type 'CGRect' (aka 'struct CGRect')
答案 0 :(得分:1)
正如Desdenova所说。
你可以这样做:
CGRect stringRect = [string boundingRectWithSize:CGSizeMake(200,300) options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:@{NSFontAttributeName:[UIFont fontWithName:self.stringLabel.font.fontName size:self.stringLabel.font.pointSize]} context:nil];
你也可以选择:
CGSize stringSize = [string boundingRectWithSize:CGSizeMake(200,300) options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:nil context:nil].size;