質問

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 !

役に立ちましたか?

解決

Use

view.clipsToBounds = YES;

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

他のヒント

set clipsToBounds = YES on view

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top