UIButton* buttonByTag = (UIButton*)[self viewWithTag:100]; //通过tag获得相应的uibutton
if( buttonByTag != nil ) [buttonByTag removeFromSuperview]; //如果button不为空,则清除之前的显示
//初始化button
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom]; button.tag = 100; UIImage* image = [GameMgr getImage:png type:1]; [button setBackgroundImage:image3 forState:0]; button.frame = CGRectMake(0, 0, 100, 100); [self addSubview:button3];
转载于:https://www.cnblogs.com/chenan/archive/2012/09/03/2669115.html