给button添加边框和圆角

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    btn.frame = CGRectMake(100, 100, 50, 50);
    
    btn.backgroundColor = [UIColor redColor];
    
    btn.layer.cornerRadius = 25;//圆角半径
    
    btn.clipsToBounds = YES;//裁剪
    
    btn.layer.borderColor = [UIColor blueColor].CGColor;//边框颜色
    
    btn.layer.borderWidth = 1;//边框的宽度
    
    [self.view addSubview:btn];

你可能感兴趣的:(给button添加边框和圆角)