UIImageView 显示在其父框架之外

Posted

技术标签:

【中文标题】UIImageView 显示在其父框架之外【英文标题】:UIImageView shows outside its parents frame 【发布时间】:2012-10-21 09:49:36 【问题描述】:

我正在为 iPad 开发 ios 应用程序,并且正在 UIView 中实现 UIImageView。问题是,如果图像视图的位置在它所在的 UIView 之外有一个位置,你可以看到它。代码:

UIView *vistafunda = [[UIView alloc] initWithFrame:CGRectMake(512/2, 48, 525, 651)];
[self.view addSubview:vistafunda];
vistafunda.backgroundColor = [UIColor darkGrayColor];

UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hola.png"]];
img.center = CGPointMake(12, 200);
[vistafunda addSubview:img];

我希望图像视图始终位于视图下方,因此如果图像在视图之外,您将看不到它。 谢谢!

【问题讨论】:

【参考方案1】:

只需将包含的视图剪辑设为子视图

vistafunda.clipsToBounds = YES;

【讨论】:

以上是关于UIImageView 显示在其父框架之外的主要内容,如果未能解决你的问题,请参考以下文章