문제

Just having some hard time with UIButton. I remove all subviews using

for (UIView *v in button.subviews) {
    [v removeFromSuperview];
}

But I want to set the background image afterwards using

[button setBackgroundImage:[UIImage imageNamed:@"backgroundImage.png"] forState:UIControlStateNormal];

and nothing happens. If I do not remove all subviews than the previous code works.

So is it possivle that removing all subviews actually removes the backgroundImage as well, in which case, is it possible to put the backgroundImage back in?

도움이 되었습니까?

해결책

Yes, according to what you experienced, the background image seems to be shown using a separate subview. Short answer: instead of raping poor view hierarchy (which is private anyway), you should keep track of the subviews you added yourself and remove only those.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top