开发者

use Aspect Fit mode with Draw-in-Rect method

i want to use Aspect Fit Mode in Draw in Rect Method.

[mainImageView.image drawInRect:CGRectMake(0, 0,mainImageView.frame.size.width,mainImageView.frame.size.height)]; 

when i show an image in MainImage View it show in scale to fill mode . I want to show it in Aspect to Fit Mode. how can i do it.can someone help开发者_运维知识库 me.


Implement it in below way:

UIImageView *imgBg = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 195.0, 39.0)];

[imgBg setImage:[UIImage imageNamed:@"bg_dropdown.png"]];

[imgBg setContentMode:UIViewContentModeScaleAspectFit];

Let me know in case of any difficulty.

Cheers


Probably you forgot to mention

[self addSubview:imgBg];

at the end of the code


If all what you want is just:

I want to show it in Aspect to Fit Mode

You can set content mode of your Image View:

mainImageView.contentMode = UIViewContentModeScaleAspectFit;

But if you want your image to be drawn in the graphics context with that content mode, you can draw the whole view instead of using drawInRect:

mainImageView.contentMode = UIViewContentModeScaleAspectFit;
[mainImageView drawViewHierarchyInRect:view.bounds 
                    afterScreenUpdates:NO];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜