将子图层的颜色设置为想要按钮的颜色(不要设置按钮本身的背景颜色),并将其矩形插入到按钮的矩形中,
- (void) awakeFromNib {
self.layer.cornerRadius = 6.0f;
self.layer.borderWidth = 4.0f;
self.layer.borderColor = [[UIColor colorWithWhite:1.0f alpha:0.5f] CGColor];
CALayer *sub = [CALayer new];
sub.frame = CGRectInset(self.bounds, 4, 4);
sub.backgroundColor = [UIColor redColor].CGColor;
[self.layer addSublayer:sub];
}

另一种方式来做到这一点,如果你想要的背景颜色过于圆润,这将更好地工作,是用背景色self.layer和子层两者。在这种情况下,所有人都需要使用边框。
- (void) awakeFromNib {
self.layer.cornerRadius = 6.0f;
self.tintColor = [UIColor whiteColor]; // make white text
self.layer.backgroundColor = [[UIColor colorWithWhite:1.0f alpha:0.4] CGColor];
CALayer *sub = [CALayer new];
sub.cornerRadius = 4.0f;
sub.frame = CGRectInset(self.bounds, 4, 4);
sub.backgroundColor = [UIColor blueColor].CGColor;
[self.layer addSublayer:sub];
}
