gpt4 book ai didi

ios - 如何修复与 sizeWithFont 和 drawAtPoint 相关的折旧警告?

转载 作者:行者123 更新时间:2023-11-29 03:13:31 24 4
gpt4 key购买 nike

我正在尝试将为 iOS 7 之前版本编写的示例代码合并到我的演示项目中。我得到一些与 drawAtPointsizeWithFont 相关的折旧方法。我已经阅读了一堆具有相同问题的 SO 条目,但它们都与标签和 tableview 单元格等相关。我正在尝试将 pdf 绘制到我的 View 中,但不知何故我无法想出正确的代码集用新方法。我真的很感激任何帮助的人。这是我正在使用的类(class)的一部分:

UIFont* studentNameFont = [UIFont boldSystemFontOfSize:17];
UIFont* classFont = [UIFont systemFontOfSize:15];

CGFloat currentPageY = 0;

for (NSDictionary* student in students)
{
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, kDefaultPageWidth, kDefaultPageHeight), nil);
currentPageY = kMargin;

NSString* name = [NSString stringWithFormat:@"%@ %@",
[student objectForKey:@"FirstName"],
[student objectForKey:@"LastName"]];

// depreciated method
CGSize size = [name sizeWithFont:studentNameFont forWidth:maxWidth lineBreakMode:NSLineBreakByWordWrapping];

//depreciated method
[name drawAtPoint:CGPointMake(kMargin, currentPageY) forWidth:maxWidth withFont:studentNameFont lineBreakMode:NSLineBreakByWordWrapping];
currentPageY += size.height;

CGContextSetStrokeColorWithColor(context, [[UIColor blueColor] CGColor]);
CGContextMoveToPoint(context, kMargin, currentPageY);
CGContextAddLineToPoint(context, kDefaultPageWidth - kMargin, currentPageY);
CGContextStrokePath(context);

NSArray* classes = [student objectForKey:@"Classes"];
for(NSDictionary* class in classes)
{
NSString* className = [class objectForKey:@"Name"];
NSString* grade = [class objectForKey:@"Grade"];

//depreciated method
size = [className sizeWithFont:classFont constrainedToSize:CGSizeMake(classNameMaxWidth, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping];

// if the current text would render beyond the bounds of the page,
// start a new page and render it there instead
if (size.height + currentPageY > maxHeight) {
// create a new page and reset the current page's Y value
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, kDefaultPageWidth, kDefaultPageHeight), nil);
currentPageY = kMargin;
}
//depreciated method
[className drawInRect:CGRectMake(kMargin, currentPageY, classNameMaxWidth, maxHeight) withFont:classFont lineBreakMode:NSLineBreakByWordWrapping alignment:NSTextAlignmentLeft];

//depreciated method
[grade drawInRect:CGRectMake(kMargin + classNameMaxWidth + kColumnMargin, currentPageY, gradeMaxWidth, maxHeight) withFont:classFont lineBreakMode:NSLineBreakByWordWrapping alignment:NSTextAlignmentLeft];

currentPageY += size.height;

}

最佳答案

你可以用这个方法

[className sizeWithAttributes:@{NSFontAttributeName:classFont}];

关于ios - 如何修复与 sizeWithFont 和 drawAtPoint 相关的折旧警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21956740/

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