Unity3D4.6 UIButton怎么修改Button背景颜色?
btnObj.GetComponent<Image>().color=new(255,24,24,255);我想改变Button的颜色,怎么改不了啊,非常明确的知道这个按...
btnObj.GetComponent<Image>().color= new (255,24,24,255);
我想改变Button 的颜色,怎么改不了啊,非常明确的知道这个按钮,怎么用代码实现背景颜色的修改,
求教?
谢谢! 展开
我想改变Button 的颜色,怎么改不了啊,非常明确的知道这个按钮,怎么用代码实现背景颜色的修改,
求教?
谢谢! 展开
展开全部
UIButton *touristBtn = [[UIButton alloc]initWithFrame:CGRectMake(20, 5, 120, 25)];
[touristBtn setBackgroundColor:[UIColor clearColor]];
[touristBtn setImage:[UIImage imageNamed:@"firstBtn.png"] forState:UIControlStateNormal];
[touristBtn setImage:[UIImage imageNamed:@"secondBtn.png" forState:UIControlStateSelected];
[touristBtn addTarget:self action:@selector(touristEvent:) forControlEvents:UIControlEventTouchUpInside];
[tabView addSubview:touristBtn];
在button的action方法中改变button的状态:
-(void)touristEvent:(id)sender{
UIButton *button = (UIButton *)sender;
button.selected = !button.selected;
}
[touristBtn setBackgroundColor:[UIColor clearColor]];
[touristBtn setImage:[UIImage imageNamed:@"firstBtn.png"] forState:UIControlStateNormal];
[touristBtn setImage:[UIImage imageNamed:@"secondBtn.png" forState:UIControlStateSelected];
[touristBtn addTarget:self action:@selector(touristEvent:) forControlEvents:UIControlEventTouchUpInside];
[tabView addSubview:touristBtn];
在button的action方法中改变button的状态:
-(void)touristEvent:(id)sender{
UIButton *button = (UIButton *)sender;
button.selected = !button.selected;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询