美文网首页
给UIButton添加背景图片

给UIButton添加背景图片

作者: 哎呦我去叫什么呢 | 来源:发表于2016-03-23 14:17 被阅读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];

相关文章

网友评论

      本文标题:给UIButton添加背景图片

      本文链接:https://www.haomeiwen.com/subject/ueenkttx.html