开发者

Trouble using [UIImageView stretchableImageWithLeftCapWidth: topCapHeight:]

开发者 https://www.devze.com 2023-03-23 01:21 出处:网络
I was just using this method in order to avoid stretching of an image. This 开发者_StackOverflowis how its been used.

I was just using this method in order to avoid stretching of an image. This 开发者_StackOverflowis how its been used. [aImgView setImage:[[UIImage imageNamed: @"dummy.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:30.0]]

but still the image is stretching to fill the entire frame. Are there any properties need to be set prior using this or something is missed here? any clarifications are helpful..


Use this line with your code:

aImgView.contentMode = UIViewContentModeScaleAspectFit;


I understand your question as if you would like the top 30 pixels to stay non-stretched while you want the rest of the picture to stretch.

I never got stretchableImageWithLeftCapWidth to work on iOS. However the following works great:

[aImgView setImage:[[UIImage imageNamed:@"dummy.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(30, 0, 30, 0) resizingMode:UIImageResizingModeStretch]];

You would certainly want to set it to

aImgView.contentMode = UIViewContentModeScaleToFill;

otherwise the whole button will stretch taking the aspect into consideration

0

精彩评论

暂无评论...
验证码 换一张
取 消