I want to know how can i use this property for UIImageView.
Overview. Image views let you efficiently draw any image that can be specified using a UIImage object. For example, you can use the UIImageView class to display the contents of many standard image files, such as JPEG and PNG files.
UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .
The first step is to drag the UIImageView onto your view. Then open the UIImageView properties pane and select the image asset (assuming you have some images in your project). You can also configure how the underlying image is scaled to fit inside the UIImageView.
For example: UIImage *img = [[UIImage alloc] init]; [img setImage:[UIImage imageNamed:@"anyImageName"]]; My UIImage object is declared in .
Stretching properties are pretty simple, as stated by Karol Kozub in this article:
The fraction of the original image left without stretching on the left is specified by X
The fraction of the original image that gets stretched in the x-axis is specified by Width
The fraction of the original image left without stretching on the right is equal to 1 – X – Width
If we use 0 for Width the stretched area will interpolate between the last pixel of the left part and the first pixel of the right part
The y-axis works analogously
This sets the contentStretch
property for views (this is a UIView
property, not specifically a UIImageView
property). This property has been deprecated since iOS 6, however, so you shouldn't use it.
The replacement, specifically for images, is resizableImageWithCapInsets
. The normal use of this is to create an image with a left and right side (or top and bottom), and a single-pixel wide "middle" that is stretched across the view. It's common for custom buttons both because it's flexible to a variety of widths, and because it saves some space.
See "Defining a Stretchable Image" in the UIImage docs for full details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With