Mar*_*ell 121 iphone rounded-corners uiimageview ios
我有点失落.我已经使用UIView的图层属性来围绕我的应用程序中的多个元素的角落.但是,这一个UIImageView根本就不符合.不确定我错过了什么.
UIImageView(称为previewImage)包含在表视图单元格中.我已经尝试将cornerRadius属性设置为多个位置(在单元格本身和创建单元格的控制器中)无济于事.
static NSString *CellIdentifier = @"MyTableViewCell";
MyTableViewCell *cell = (MyTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil];
cell = [topLevelObjects objectAtIndex:0];
cell.previewImage.layer.cornerRadius = 20; //Made it 20 to make sure it's obvious.
}
Run Code Online (Sandbox Code Playgroud)
有没有关于细胞加载的方式,我错过了?
Eva*_*ski 363
您需要将图层的masksToBounds属性设置为YES:
cell.previewImage.layer.masksToBounds = YES;
这是因为UIImageView控件创建了一个伪子视图来保存UIImage对象.
Nai*_*hta 24
另外值得注意的是
即如果你有这个
theImageView.contentMode = .scaleAspectFit
Run Code Online (Sandbox Code Playgroud)
和
theImageView.layer.cornerRadius = (theImageView.frame.size.height)/2
theImageView.clipsToBounds = true
Run Code Online (Sandbox Code Playgroud)
要么
theImageView.layer.masksToBounds = true
Run Code Online (Sandbox Code Playgroud)
它不会起作用.你将不得不摆脱aspectFit代码
//theImageView.contentMode = .scaleAspectFit
Run Code Online (Sandbox Code Playgroud)
Tee*_*aul 22
这应该工作
cell.previewImage.clipsToBounds = YES;
cell.previewImage.layer.cornerRadius = 20;
Run Code Online (Sandbox Code Playgroud)
Dan*_*son 11
我相信你需要设置:
cell.previewImage.layer.masksToBounds = YES;
cell.previewImage.layer.opaque = NO;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
82391 次 |
| 最近记录: |