有人知道如何在這種情況下使用-boundingRectWithSize:options:attributes:context:替代棄用的「sizeWithFont:constrainedToSize:」方法。棄用'sizeWithFont:constrainedToSize:'替換
CGSize labelSize = [self.mainLabel.text sizeWithFont:self.mainLabel.font constrainedToSize:CGSizeMake(CGFLOAT_MAX, CGRectGetHeight(self.bounds))];
獲取警告: 'sizeWithFont:constrainedToSize:' 已過時:在IOS 7.0第一棄用 - 使用-boundingRectWithSize:選項:屬性:背景:
這是孔這段代碼:
// calculate the label size
CGSize labelSize = [self.mainLabel.text sizeWithFont:self.mainLabel.font constrainedToSize:CGSizeMake(CGFLOAT_MAX, CGRectGetHeight(self.bounds))];
each_object(self.labels, ^(UILabel *label) {
CGRect frame = label.frame;
frame.origin.x = offset;
frame.size.height = CGRectGetHeight(self.bounds);
frame.size.width = labelSize.width + 2.f /*Magic number*/;
label.frame = frame;
// Recenter label vertically within the scroll view
label.center = CGPointMake(label.center.x, roundf(self.center.y - CGRectGetMinY(self.frame)));
offset += CGRectGetWidth(label.bounds) + self.labelSpacing;
});
謝謝!但我得到這個「沒有可見的@interface爲'NSString'聲明選擇器'boundingRectWithSize:options:context:'」 – user2023660
你可以在這裏看到它的文檔... https://developer.apple.com/library/ios /documentation/uikit/reference/NSString_UIKit_Additions/Reference/Reference.html – Fogmeister
我應該替換還是應該放在某處?在參考文獻中不要更清楚。 – user2023660