我在StackOverflow上找到了关于如何在UIImageView上做弯曲拐角的例子,并且当我在Xcode GUI构建器工具中设置图像时,此工作正常。当我在运行时添加了一些代码来更改图像时,弯曲的角部分只能部分工作。即使在运行时设置UIImage,如何在UIImageView上做弯曲的角点?
这里是我使用的尝试,并取得弯角代码:
thumbnail.image = [UIImage imageNamed:self.video.thumbnailFileName];
thumbnail.contentMode = UIViewContentModeScaleAspectFill;
thumbnail.clipsToBounds = YES;
// round the corners:
thumbnail.layer.cornerRadius = 10.0;
thumbnail.layer.masksToBounds = YES;
// add a border:
thumbnail.layer.borderColor = [UIColor lightGrayColor].CGColor;
thumbnail.layer.borderWidth = 3.0;
BEFORE:当通过GUI Builder将在Xcode设置图像:
AFTER:设置UIImage的编程。注意弧形的角部看起来可怕:
原始的PNG图像在应用程序中使用: