Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is use of stretching property of UIImageView. How I can use this property.?

enter image description here

I want to know how can i use this property for UIImageView.

like image 518
Shreyank Avatar asked May 24 '16 12:05

Shreyank


People also ask

What is use of 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.

What is the difference between a UIImage and a UIImageView?

UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .

How do I add an image to UIImageView?

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.

How do you declare UIImage in Objective C?

For example: UIImage *img = [[UIImage alloc] init]; [img setImage:[UIImage imageNamed:@"anyImageName"]]; My UIImage object is declared in .


2 Answers

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

like image 133
Klevison Avatar answered Oct 14 '22 14:10

Klevison


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.

like image 38
Rob Napier Avatar answered Oct 14 '22 12:10

Rob Napier