2017-08-09 34 views
0

我需要更改我的自定义类按钮的bg颜色,由UIViewUIButton组成。更改UIView背景颜色重置圆角

- (instancetype)initWithFrame:(CGRect)frame color:(UIColor*)color imageName:(NSString*)imageName target:(id)target action:(SEL)action tag:(int)tag{ 

    self = [super init]; 

    if (self) { 

     self.frame = frame; 

     CircleStatusView * view = [[CircleStatusView alloc]initWithFrame:self.bounds color:color]; 
     view.tag = 22; 
     [self addSubview:view]; 

     UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom]; 
     btn.frame = self.bounds; 
     [btn setBackgroundColor:[UIColor clearColor]]; 
     [btn setImage:[[UIImage imageNamed:imageName]imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal]; 
     [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; 
     [btn setTintColor:[UIColor whiteColor]]; 
     btn.tag = tag; 
     [self addSubview:btn]; 


    } 
    return self; 

} 

我改变UIView的backgroundColor当使用该方法按下UIButton。我从灰色变成绿色:

- (instancetype)initWithFrame:(CGRect)frame color:(UIColor*)color{ 

    self = [super init]; 

    if (self) { 

     self.frame = frame; 
     self.layer.borderColor = [UIColor whiteColor].CGColor; 
     self.layer.borderWidth = 3; 
     self.backgroundColor = color; 
     self.clipsToBounds = YES; 
     self.layer.masksToBounds = NO; 
     self.layer.cornerRadius = frame.size.width/2; 

     self.layer.shadowColor = [UIColor darkGrayColor].CGColor; 
     self.layer.shadowOffset = CGSizeMake(0, 2); 
     self.layer.shadowOpacity = 1; 
     self.layer.shadowRadius = 1.0; 

    } 
    return self; 

} 

我的问题是,鉴于圆角半径消失,认为成为一个方形的,而不是仍然是:

- (void)changeBackgroundColor:(UIColor*)color{ 

     [(CircleStatusView*)[self viewWithTag:22] setBackgroundColor:color]; 

    } 

的CircleStatusView以这种方式制成圆圈,像这样:

enter image description here

回答

0

我打电话setBackgroundColor:不是changeBackgroundColor :,阿呆错误