gpt4 book ai didi

ios - 错误: bad receiver type 'CGSize' (aka 'struct CGSize' ) | Xcode 6.4 | iOS 8.4

转载 作者:行者123 更新时间:2023-12-02 11:02:44 24 4
gpt4 key购买 nike

我在不赞成使用的方法上遇到问题,我正在尝试将其更改为现在可以正常工作,但是不走运,有人知道如何解决此问题吗?

问题是我正在编写的代码不是我的,所以我做得不太好。

这是原始代码(是不推荐使用的):

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];

这是我的解决方案( 引发错误):
CGFloat remainingHeight = bounds.size.height - totalSize.height - kPadding - 4 * margin; 
CGSize maxSize = CGSizeMake(maxWidth, remainingHeight);
CGSize detailsLabelSize = [[detailsLabel.text sizeWithAttributes:@{NSFontAttributeName:detailsLabel.font}]constrainedToSize:maxSize lineBreakMode:detailsLabel.lineBreakMode];

错误出现在标题中( 接收者类型错误的'CGSize'(aka'struct CGSize'))

非常感谢!

最佳答案

在实现文件中添加此方法:

-(CGSize)frameForText:(NSString*)text sizeWithFont:(UIFont*)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode)lineBreakMode  {

NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.lineBreakMode = lineBreakMode;

NSDictionary * attributes = @{NSFontAttributeName:font,
NSParagraphStyleAttributeName:paragraphStyle
};


CGRect textRect = [text boundingRectWithSize:size
options:NSStringDrawingUsesLineFragmentOrigin
attributes:attributes
context:nil];
return textRect.size;
}

然后将您的代码更改为:
CGSize detailsLabelSize = [self frameForText:detailsLabel.text sizeWithFont:detailsLabel.font constrainedToSize:maxSize lineBreakMode:detailsLabel.lineBreakMode];

关于ios - 错误: bad receiver type 'CGSize' (aka 'struct CGSize' ) | Xcode 6.4 | iOS 8.4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32315559/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com