iOS button setImage和setBackgroundImage的区别

代码:
//箭头
UIButton *arrowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
arrowBtn.frame = CGRectMake(kScreeenWidth * i + (kScreeenWidth - 60 - 10), (kCellHeight - 40) / 2., 60,40);
[arrowBtn setImage:[UIImage imageNamed:@"arrow_right_black.png"] forState:UIControlStateNormal];
// [arrowBtn setBackgroundImage:[UIImage imageNamed:@"arrow_right_black.png"] forState:UIControlStateNormal];
[arrowBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[arrowBtn setTitle:@"arrow" forState:UIControlStateNormal];
// arrowBtn.backgroundColor = [UIColor redColor];
[arrowBtn addTarget:self action:@selector(changeActivity) forControlEvents:UIControlEventTouchUpInside];
[_sectionScrollView addSubview:arrowBtn];

  1. setImage图片大小不会随着按钮fram改变,不会拉伸。
iOS button setImage和setBackgroundImage的区别_第1张图片
setImage.jpeg

2.setBackgroundImage图片大小会随着按钮fram改变,跟按钮frame大小可能会拉伸变形。设置的title可以显示

iOS button setImage和setBackgroundImage的区别_第2张图片
setBackgroundImage.jpeg

你可能感兴趣的:(iOS button setImage和setBackgroundImage的区别)