2

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 !

AppleDelegate
  • 4,269
  • 1
  • 20
  • 27
VivienCormier
  • 1,133
  • 1
  • 11
  • 16

3 Answers3

1

set clipsToBounds = YES on view

wattson12
  • 11,176
  • 2
  • 32
  • 34
1

Use

view.clipsToBounds = YES;

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

Eiko
  • 25,601
  • 15
  • 56
  • 71
0

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.

barley
  • 4,403
  • 25
  • 28