Flags for modifying the way cropping is handled when scaling images to fit or fill.
NINetworkImageViewScaleOptions;
Discussion
By default the network image view will behave in the following way for these content modes:
- UIViewContentModeScaleAspectFit: Leaves unfilled space as transparent.
- UIViewContentModeScaleAspectFill: Crops any excess pixels.
The resulting image size will exactly match the display size.
You can modify this behavior using the following two flags which should be set using binary operators.
NINetworkImageViewScaleToFitCropsRemainder
The final image size will be shrunk to fit the image such that there is no transparency.
NINetworkImageViewScaleToFillLeavesRemainder
The final image size will be grown to include the excess pixels.
Examples
The following examples use this image:
Dimensions: 500x375
Default settings with UIViewContentModeScaleAspectFit
Result image (display size 100x100)
Fit image with default settings leaves transparent pixels. Size: 100x100.
Example code
imageView.scaleOptions = NINetworkImageViewScaleToFitLeavesExcessAndScaleToFillCropsExcess;
[imageView setPathToNetworkImage: @"http://farm2.static.flickr.com/1165/644335254_4b8a712be5.jpg"
forDisplaySize: CGSizeMake(100, 100)
contentMode: UIViewContentModeScaleAspectFit];
source image size: 500x375 [aspect ratio: 1.3333]
display size: 100x100 [aspect ratio: 1]
result image size: 100x100 [aspect ratio: 1] (transparency on the left and right edges)
image blt size: 100x75 [aspect ratio: 1.3333]
Default settings with UIViewContentModeScaleAspectFill
Result image (display size 100x100)
Fill image with default settings chops excess pixels. Size: 100x100.
Example code
[imageView setPathToNetworkImage: @"http://farm2.static.flickr.com/1165/644335254_4b8a712be5.jpg"
forDisplaySize: CGSizeMake(100, 100)
contentMode: UIViewContentModeScaleAspectFill];
source image size: 500x375 [aspect ratio: 1.3333]
display size: 100x100 [aspect ratio: 1]
result image size: 100x100 [aspect ratio: 1]
image blt size: 133x100 [aspect ratio: 1.3333]
NINetworkImageViewScaleToFitCropsExcess with UIViewContentModeScaleAspectFit
Result image (display size 100x100)
Fit image with NINetworkImageViewScaleToFitCropsExcess crops the transparency. Size: 100x75.
Example code
imageView.scaleOptions |= NINetworkImageViewScaleToFitCropsExcess;
[imageView setPathToNetworkImage: @"http://farm2.static.flickr.com/1165/644335254_4b8a712be5.jpg"
forDisplaySize: CGSizeMake(100, 100)
contentMode: UIViewContentModeScaleAspectFill];
source image size: 500x375 [aspect ratio: 1.3333]
display size: 100x100 [aspect ratio: 1]
result image size: 100x75 [aspect ratio: 1.3333]
image blt size: 100x75 [aspect ratio: 1.3333]
NINetworkImageViewScaleToFillLeavesExcess with UIViewContentModeScaleAspectFill
Result image (display size 100x100)
Fill image with NINetworkImageViewScaleToFillLeavesExcess leaves the excess. Size: 133x100.
Example code
imageView.scaleOptions |= NINetworkImageViewScaleToFillLeavesExcess;
[imageView setPathToNetworkImage: @"http://farm2.static.flickr.com/1165/644335254_4b8a712be5.jpg"
forDisplaySize: CGSizeMake(100, 100)
contentMode: UIViewContentModeScaleAspectFill];
source image size: 500x375 [aspect ratio: 1.3333]
display size: 100x100 [aspect ratio: 1]
result image size: 133x100 [aspect ratio: 1.3333]
image blt size: 133x100 [aspect ratio: 1.3333]