gpt4 book ai didi

ios - Objective-C:如何获取 NSMutableArray 中对象的属性?

转载 作者:行者123 更新时间:2023-12-01 17:20:37 25 4
gpt4 key购买 nike

我有 UIImageNSMutableArray 名为 camImages。然后我想获取图像的 scale 属性,但我似乎无法使用

访问它
[[camImages objectAtIndex:i] scale] //doesn't return the desired scale property
[camImages.objectAtIndex:i].scale //doesn't work (Error: Property 'scale' not found on object of type 'id')

而如果我只有一个 UIImage 就可以获得该属性

UIImage *img;
img.scale //desired property

我是 iOS 和 Objective-C 的新手,如何获得所需的属性?提前致谢!

编辑:

[[camImages objectAtIndex:i] scale] 将返回

NSDecimalNumberBehaviors

Scale

Returns the number of digits allowed after the decimal separator. (required)

  • (short)scale Return Value The number of digits allowed after the decimal separator.

而所需的比例是 CGFloat 类型:

UIImage

scale

The scale factor of the image. (read-only)

@property(nonatomic, readonly) CGFloat scale Discussion If you load an image from a file whose name includes the @2x modifier, the scale is set to 2.0. You can also specify an explicit scale factor when initializing an image from a Core Graphics image. All other images are assumed to have a scale factor of 1.0.

If you multiply the logical size of the image (stored in the size property) by the value in this property, you get the dimensions of the image in pixels.

最佳答案

使您的代码更易于阅读和调试:

UIImage *image = camImages[i];
CGFloat scale = image.scale;

关于ios - Objective-C:如何获取 NSMutableArray 中对象的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20985276/

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