導入:
MBProgressHUD出警告
如:
- (CGSize)sizeWithFont:(UIFont*)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode)lineBreakModeNS_DEPRECATED_IOS(2_0,7_0,"Use -boundingRectWithSize:options:attributes:context:");
提示用:boundingRectWithSize:options:attributes:context:這個方法
CGFloat remainingHeight = bounds.size.height - totalSize.height - kPadding - 4 * margin;
CGSize maxSize = CGSizeMake(maxWidth, remainingHeight);
/*
CGSize detailsLabelSize = [detailsLabel.text sizeWithFont:detailsLabel.font
constrainedToSize:maxSize lineBreakMode:detailsLabel.lineBreakMode];*/
NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:20]};
CGSize detailsLabelSize = [detailsLabel.text boundingRectWithSize:maxSize options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
以及
- (CGSize)sizeWithFont:(UIFont *)font NS_DEPRECATED_IOS(2_0, 7_0, "Use -sizeWithAttributes:") __TVOS_PROHIBITED;
如下寫法
CGSize labelSize = [label.text sizeWithAttributes:@{NSFontAttributeName:label.font}];
幾個參數:
size:范圍自己決定
options :這是一個枚舉類型
typedefNS_ENUM(NSInteger, NSStringDrawingOptions) {
NSStringDrawingTruncatesLastVisibleLine = 1 << 5,
NSStringDrawingUsesLineFragmentOrigin = 1 <<0,
NSStringDrawingUsesFontLeading = 1 <<1,
NSStringDrawingUsesDeviceMetrics = 1 <<3,
} NS_ENUM_AVAILABLE_IOS(6_0);
自己選一個適合的
attributes:字典
NSDictionary *attributes = @{NSFontAttributeName:[UIFontsystemFontOfSize:20]};
context:文本繪制的規范定義,一半為nil就可以
其他的大家觸類旁通把