您好我的代码有问题。
请不要判断,第一次试图找出一些错误。我收到一个"不兼容的指针类型,发送' UIFount *'到类型参数' NSDictionary * _Nullable'"
这是代码。任何帮助表示赞赏...
// Entirely cover the parent view
UIView *parent = self.superview;
if (parent) {
self.frame = parent.bounds;
}
CGRect bounds = self.bounds;
// Determine the total widt and height needed
CGFloat maxWidth = bounds.size.width - 4 * margin;
CGSize totalSize = CGSizeZero;
CGRect indicatorF = indicator.bounds;
indicatorF.size.width = MIN(indicatorF.size.width, maxWidth);
totalSize.width = MAX(totalSize.width, indicatorF.size.width);
totalSize.height += indicatorF.size.height;
//**Issue is HERE**
CGSize labelSize = [label.text sizeWithAttributes: label.font];
labelSize.width = MIN(labelSize.width, maxWidth);
totalSize.width = MAX(totalSize.width, labelSize.width);
totalSize.height += labelSize.height;
if (labelSize.height > 0.f && indicatorF.size.height > 0.f) {
totalSize.height += kPadding;
}
CGFloat remainingHeight = bounds.size.height - totalSize.height - kPadding - 4 * margin;
CGSize maxSize = CGSizeMake(maxWidth, remainingHeight);
CGSize detailsLabelSize = [detailsLabel.text sizeWithAttributes: detailsLabel.font
constrainedToSize:maxSize lineBreakMode:detailsLabel.lineBreakMode];
totalSize.width = MAX(totalSize.width, detailsLabelSize.width);
totalSize.height += detailsLabelSize.height;
if (detailsLabelSize.height > 0.f && (indicatorF.size.height > 0.f || labelSize.height > 0.f)) {
totalSize.height += kPadding;
}
totalSize.width += 2 * margin;
totalSize.height += 2 * margin;
答案 0 :(得分:1)
sizeWithAttribute
期待NSDictionary
你正在传递UIFont
,这就是你收到此警告的原因,制作一个这样的字典
NSDictionary *attributes = @{NSFontAttributeName: [UIFont fontWithName:@"YourFontName" size:YourFontSize]};
然后传递此属性字典
CGSize labelSize = [label.text sizeWithAttributes: attributes];