在UIImage - iPhone SDK上绘制一个透明圆圈

Bre*_*ett 2 iphone objective-c uiimageview

我在尝试找到如何在UIImageView中的UIImage上绘制透明圆圈时遇到了很多麻烦.Google-ing给了我线索,但我仍然找不到一个有效的例子.

是否有任何人都知道的例子证明了这一点?

iam*_*4de 11

最简单的方法是创建一个半透明的方形UIView,然后将其图层的cornerRadius设置为其宽度/高度的一半.就像是:

UIView *squareView = [[UIView alloc] initWithFrame:CGRectMake(0,0,100,100)];
squareView.alpha = 0.5;
squareView.layer.cornerRadius = 50;
...
[squareView release];
Run Code Online (Sandbox Code Playgroud)

  • 你忘了squareView.clipsToBounds = YES; 没有它,这是行不通的. (3认同)