Coloration of UIButtons of type UIButtonTypeRoundedRect

后端 未结 4 1305
闹比i
闹比i 2021-01-19 14:38

I would like the rounded rectangle portion of the subject type of UIButton to be a solid custom color I specify. I understand that

. setTitleColor : changes the tex

4条回答
  •  逝去的感伤
    2021-01-19 15:14

    Try

    CALayer *subLayer = [CALayer layer];
    subLayer.frame = self.theButton.bounds;
    subLayer.cornerRadius = 10.0;
    subLayer.opacity = 1.0;
    
    CALayer *imageLayer = [CALayer layer];
    imageLayer.frame = subLayer.bounds;
    imageLayer.cornerRadius = 10.0;
    
    
    imageLayer.masksToBounds = YES;
    imageLayer.opacity = 1.0;
    imageLayer.contents = (id) [UIImage imageNamed:@"your.png"].CGImage;
    
    [subLayer addSublayer:imageLayer];
    
    [self.theButton.layer addSublayer:subLayer];
    

提交回复
热议问题