如果這不是工作了,做一個組成部分。 UIView的子類。請在此子類上更改:
subclass.layer.cornerRadius = subclass.frame.size.width/2;
subclass.layer.masksToBounds = YES;
並將imageView添加到此視圖。這將解決問題。
@implementation CircleImageView{
UIImageView* imageView;
CGFloat width;
}
- (instancetype) initWithTopLeft:(CGPoint)topLeft width:(CGFloat)wdth{
self = [super initWithFrame:CGRectMake(topLeft.x, topLeft.y, wdth, wdth)];
if (self) {
width = wdth;
[self createContent];
self.layer.cornerRadius = width/2.;
self.clipsToBounds = YES;
}
return self;
}
- (void) createContent{
imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, width, width)];
[self addSubview:imageView];
}
如果這是真的不工作,我的應用程序會崩潰:/ –
這不是崩潰 - 但它保持矩形 – YogevSitton
我只是檢查,但它確實工作。你可以改變dot.frame.size.width/2來說4嗎? – tafh