Search code examples
objective-ciosuiimageviewscalecontentmode

UiimageView adapted in a uiview


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 !


Solution

  • Use

    view.clipsToBounds = YES;
    

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