我在Xcode中收到警告:
Format指定类型'int'但参数具有类型 'UIViewContentMode'
我有一个方法可用于调整UIImage
的大小,如下所示:
- (UIImage *)resizedImageWithContentMode:(UIViewContentMode)contentMode
bounds:(CGSize)bounds
interpolationQuality:(CGInterpolationQuality)quality {
CGFloat horizontalRatio = bounds.width / self.size.width;
CGFloat verticalRatio = bounds.height / self.size.height;
CGFloat ratio;
switch (contentMode) {
case UIViewContentModeScaleAspectFill:
ratio = MAX(horizontalRatio, verticalRatio);
break;
case UIViewContentModeScaleAspectFit:
ratio = MIN(horizontalRatio, verticalRatio);
break;
default:
[NSException raise:NSInvalidArgumentException format:@"Unsupported content mode: %d", contentMode];
}
...
UIViewContentMode
似乎引用了一个Integer,所以我不确定这个警告:
typedef NS_ENUM(NSInteger, UIViewContentMode) {
UIViewContentModeScaleToFill,
UIViewContentModeScaleAspectFit, // contents scaled to fit with fixed aspect. remainder is transparent
UIViewContentModeScaleAspectFill, ...
我怎样摆脱这个警告似乎不正确?异常中的NSLog
是否正确?
答案 0 :(得分:1)
您可以将NSInteger
UIViewContentMode
投射到这样的int
:
[NSException raise:NSInvalidArgumentException format:@"Unsupported content mode: %d", (int)contentMode];