给UIButton添加背景图片

2016-03-23  本文已影响106人  哎呦我去叫什么呢

给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];

上一篇 下一篇

猜你喜欢

热点阅读