ios - 不兼容的指针类型 xcode 8

标签 ios objective-c xcode uifont

您好,我的代码有问题。
请不要判断,第一次尝试找出一些错误。我收到“不兼容的指针类型发送‘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;

最佳答案

sizeWithAttribute 期望一个 NSDictionary 并且您在其中传递 UIFont,这就是您收到此警告的原因,制作这样的字典

NSDictionary *attributes = @{NSFontAttributeName: [UIFont fontWithName:@"YourFontName" size:YourFontSize]};

然后传递这个属性字典

CGSize labelSize = [label.text sizeWithAttributes: attributes];

关于ios - 不兼容的指针类型 xcode 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40826816/

相关文章:

ios - 在 `touchesBegan:withEvent:` 之后禁用所有 UIPanGestureRecognizers

ios - 访问 NSDictionary 时收到 SIGABRT

objective-c - Objective C 中的环境变量列表?

objective-c - 通过扩展使现有的 Objective C 类符合 swift 协议(protocol)

ios - 用于将框架链接和嵌入到工作区中的应用程序的 Xcode 构建过程

ios - UITextView 像 iOS 邮件应用程序一样增加高度

ios - Objective-c:UIStackView 的动态大小,取决于它的内容

ios - 检测 Touch ID 已启用

ios - 使用 Storyboard在 UILabel 中的文本前后添加一个空格

ios - 在应用程序切换器中更新 UI