首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不兼容的指针类型xcode 8

不兼容的指针类型xcode 8
EN

Stack Overflow用户
提问于 2016-11-27 15:46:31
回答 1查看 71关注 0票数 0

您好,我的代码有一些问题。

请不要评判,第一次尝试找出一些错误。我收到“不兼容的指针类型发送‘UIFount*’到‘NSDictionary*_Nullable’类型的参数”

下面是代码。任何帮助我们都很感激。

代码语言:javascript
复制
// 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;
EN

回答 1

Stack Overflow用户

发布于 2016-11-27 15:55:03

sizeWithAttribute期望一个NSDictionary,而你在它里面传递了UIFont,这就是为什么你会得到这个警告,做一个这样的字典

代码语言:javascript
复制
NSDictionary *attributes = @{NSFontAttributeName: [UIFont fontWithName:@"YourFontName" size:YourFontSize]};

然后传递这个属性字典

代码语言:javascript
复制
CGSize labelSize = [label.text sizeWithAttributes: attributes];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40826816

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档