Format指定类型'int'但参数的类型为'UIViewContentMode'

时间:2013-12-08 22:18:38

标签: ios objective-c ios6 uiview ios7

我在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是否正确?

1 个答案:

答案 0 :(得分:1)

您可以将NSInteger UIViewContentMode投射到这样的int

[NSException raise:NSInvalidArgumentException format:@"Unsupported content mode: %d", (int)contentMode];