【发布时间】:2015-04-03 01:18:18
【问题描述】:
引用this answer,我正在尝试使 UIImageView 显示圆形图像。我生成了一个蒙版并尝试使用该图像对其进行蒙版,但也没有用。
当我尝试遮盖图像或更改角落时,没有任何反应。
就是这样:
[proPic.layer setCornerRadius:proPic.frame.size.width/2];
当我打电话给[proPic.layer setMasksToBounds:YES]; 时,图像完全消失了。当我尝试使用third party library 来屏蔽图像时也是如此。
有什么建议吗?
编辑:
//Profile Picture
proPic = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"DummyProPic"]];
//Mask Profile Picture to be circular
[proPic.layer setCornerRadius:proPic.frame.size.width/2];
//With this line added, the picture disappears
//Without this line, nothing is done to mask the image
[proPic.layer setMasksToBounds:YES];
[self.contentView addSubview:proPic];
[proPic mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView.mas_top).with.offset(padding.top);
make.centerX.equalTo(self.contentView.mas_centerX);
make.height.equalTo(@120);
make.width.equalTo(@120);
}];
【问题讨论】:
-
你能发布你的代码吗?
-
您的代码看起来不错,您确定
proPic是用IBOutlet声明的,并且在左侧(行号旁边),有一个小实心圆圈表示有与您的故事板的连接(假设您正在使用它)? -
我没有使用故事板。我会看看我是否有更多相关的代码。
-
如果去掉cornerRadius代码,图像是否仍然丢失?
-
不,如果我移除角线,图像将保持未遮盖状态,就好像什么都没做一样。
标签: ios user-interface calayer