我如何以编程方式创建一个 UIView,里面有一个 'cutoff' UIImageView?
How can I programmatically create a UIView, with a 'cutoff' UIImageView inside of it?
假设我想创建一个宽度和高度为 100x200 的 UIView。
然后,我想创建一个大小为 100x300 的 UIImageView(因为这是我的图像的大小)。
但是,我希望将图像底部的 100px 切掉。当我现在这样做时,UIImageView 似乎将我的 UIView 的大小扩大到 100x300,而不是原来的 100x200。
这是我的代码。我怎样才能做到这一点?
UIView *screeshotView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100.0, 200.0)];
UIImageView *phoneView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 300.0)];
UIImage *phoneImage = [UIImage imageNamed:@"iPhone_6_White.png"];
phoneView.image = phoneImage;
[screeshotView addSubview:phoneView];
有一个 属性 称为 clipsToBounds(默认为 false)。它在所有 UIView 中。
就做
screeshotView.clipsToBounds = true;
这应该会切断屏幕截图视图框架之外的任何内容
假设我想创建一个宽度和高度为 100x200 的 UIView。
然后,我想创建一个大小为 100x300 的 UIImageView(因为这是我的图像的大小)。
但是,我希望将图像底部的 100px 切掉。当我现在这样做时,UIImageView 似乎将我的 UIView 的大小扩大到 100x300,而不是原来的 100x200。
这是我的代码。我怎样才能做到这一点?
UIView *screeshotView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100.0, 200.0)];
UIImageView *phoneView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 300.0)];
UIImage *phoneImage = [UIImage imageNamed:@"iPhone_6_White.png"];
phoneView.image = phoneImage;
[screeshotView addSubview:phoneView];
有一个 属性 称为 clipsToBounds(默认为 false)。它在所有 UIView 中。
就做
screeshotView.clipsToBounds = true;
这应该会切断屏幕截图视图框架之外的任何内容