我的UIImageView有点问题。 我希望UIImageView的内容不会溢出到UIView。
当我尝试使用此代码时,我得到了这个结果,但是我不会在条纹区域中使用图像。
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];
我尝试了很多属性,“contentMode”和“autorezingMask”但是我没有很好的结果。
谢谢!
答案 0 :(得分:1)
在视图
上设置clipsToBounds = YES
答案 1 :(得分:1)
使用
view.clipsToBounds = YES;
这会导致其子视图被剪切到接收器边界。
答案 2 :(得分:0)
我并非100%清楚您想要实现的目标,但您想要的可能是UIViewContentModeScaleAspectFit
而不是UIViewContentModeScaleAspectFill
。
此外,您首先在300x100中创建UIImageView
帧并重置为320x100。我相信重置部分不是你的意图。