UiimageView adapted in a uiview

151 views Asked by At

I have a little problem with my UIImageView. I want the content of UIImageView don't overflow to UIView.

When I tryed this code, I have this result, but I won't a image in area striped.

UIView *view = [[UIView alloc] init];
[view setFrame:CGRectMake(10, 0, 300, 100)];
[self.view addSubview:view];

UIImageView *viewimageArticle = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 100)];
viewimageArticle.image =[UIImage imageNamed:@"article1.jpeg"];
viewimageArticle.contentMode = UIViewContentModeScaleAspectFill;
viewimageArticle.frame = CGRectMake(0, 0, 320, 100);
[view addSubview:viewimageArticle];

enter image description here

I tryed a many properties, "contentMode" and "autorezingMask" but i don't have good result.

Thank you !

3

There are 3 answers

0
Eiko On BEST ANSWER

Use

view.clipsToBounds = YES;

This causes its subviews to be clipped to the receivers bounds.

0
wattson12 On

set clipsToBounds = YES on view

0
barley On

I am not 100% clear of what you want to achieve, but what you want may be UIViewContentModeScaleAspectFit instead of UIViewContentModeScaleAspectFill.

Also, you are creating the UIImageView frame in 300x100 first and resetting to 320x100. I believe the resetting part is not your intention.