我得到了不兼容的指针类型,将 UIFont 发送到 NSDictonary 类型的参数,这让我得到一个 SIGABRT 信号,我不知道这是什么意思,我的代码在...中出现错误
- (void)drawDayNumber {
if (self.selectionState == DSLCalendarDayViewNotSelected) {
[[UIColor colorWithWhite:66.0/255.0 alpha:1.0] set];
}
else {
[[UIColor whiteColor] set];
}
UIFont *textFont = [UIFont boldSystemFontOfSize:17.0];
CGSize textSize = [_labelText sizeWithAttributes:textFont];//Im getting it here.
CGRect textRect = CGRectMake(ceilf(CGRectGetMidX(self.bounds) - (textSize.width /2.0)), ceilf(CGRectGetMidY(self.bounds) - (textSize.height / 2.0)), textSize.width, textSize.height);
[_labelText drawInRect:textRect withAttributes:textFont];//And here.
}
最佳答案
崩溃 1
问题在于此代码:
[_labelText drawInRect:textRect withAttributes:textFont];
drawInRect:withAttributes:
方法的第二个参数需要 NSDictionary
,您正在传递 UIFont
对象。这就是崩溃的原因。
你应该这样做:
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys: textFont,NSFontAttributeName,nil];
[_labelText drawInRect:textRect withAttributes:dict];
或
您可以使用:drawInRect:withFont
方法。
[_labelText drawInRect:rect withFont:textFont];
崩溃 2
在下面的代码中:
CGSize textSize = [_labelText sizeWithAttributes:textFont];
这里的参数也是错误的,sizeWithAttributes:
方法需要NSDictionary
,你传递的是UIFont
对象。
将其更改为:
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys: textFont,NSFontAttributeName,nil];
CGSize textSize = [_labelText sizeWithAttributes:dict];
关于ios - 不兼容的指针类型将 UIFont 发送到 NSDictonary 类型的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19440784/