setBackgroundImage和setImage这两个还是有区别的
例如:
当你需要设置按钮的frame为当前图片的frame时候,如果用setImage,那么frame为nil 这时,只能用setBackgroundImage 才能使得按钮的frame为image的frame
UIButton * backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[backBtn setImage:[UIImage imageNamed:@"---"] forState:UIControlStateNormal];
CGRect tempFrame = backBtn.frame;
tempFrame.size = backBtn.currentBackgroundImage.size;
backBtn.frame = tempFrame;
此时,backBtn的frame 为nil
UIButton * backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[backBtn setBackgroundImage:[UIImage imageNamed:@"---"] forState:UIControlStateNormal];
CGRect tempFrame = backBtn.frame;
tempFrame.size = backBtn.currentBackgroundImage.size;
backBtn.frame = tempFrame;
此时,backBtn的frame 为image的frame