给UIButton添加背景图片

给UIButton添加背景图片

//定义一个button

UIButton * button = [UIButton buttonWithType:(UIButtonTypeRoundedRect)];

//大小

button.frame =CGRectMake(10, 10, 50, 50);

//设置成圆形(根据需要)

button.layer.cornerRadius = button.frame.size.width /2;

button.clipsToBounds = YES;

//调用添加图片的方法

[button setBackgroundImage:[UIImage imageNamed:@"add.png"] forState:(UIControlStateNormal)];

[self.view addSubview:button];

你可能感兴趣的:(给UIButton添加背景图片)