Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c UIView图层圆角和-drawRect:_Objective C_Cocoa Touch - Fatal编程技术网

Objective c UIView图层圆角和-drawRect:

Objective c UIView图层圆角和-drawRect:,objective-c,cocoa-touch,Objective C,Cocoa Touch,是否可以在UIView的图层上设置圆角,同时覆盖-drawRect:?当前,-drawRect:调用似乎覆盖了层的圆角,并使其再次呈现角度,即使-drawRect:仅包含对super的-drawRect:的调用,将不透明属性设置为否。您将获得圆角 -(id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if(self) { self.layer.cornerRadius

是否可以在
UIView
的图层上设置圆角,同时覆盖
-drawRect:
?当前,
-drawRect:
调用似乎覆盖了层的圆角,并使其再次呈现角度,即使
-drawRect:
仅包含对super的
-drawRect:

的调用,将不透明属性设置为否。您将获得圆角

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self)
    {
        self.layer.cornerRadius = KCORNERRAD;
        self.opaque = NO;

    }
    return self;
}

self.opaque=NO
对我不起作用。设置
self.layer.masksToBounds=YES
确实有效(在iOS 4.3上测试):


这里也一样
self.opaque=NO
没有这样做,但是
masksToBounds=YES
做了。
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if( self )
    {
        self.layer.cornerRadius = 6.0f;
        self.layer.masksToBounds = YES;
    }
    return self;
}