答案 0 :(得分:2)
这里有很多不同的可能性:
1)确实用另一种颜色制作新图像。快速入门,但不是很灵活。
2)它看起来很像矢量图形图标。您可以使用贝塞尔曲线绘制整个图标,然后您可以为任何颜色着色。还有一些工具可以为您生成代码(例如PaintCode)。
3)你可以使用一些过滤器(见这里:https://developer.apple.com/library/prerelease/mac/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html)
答案 1 :(得分:1)
玩这个:
func changeColor() {
theImageView.image = theImageView.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
theImageView.tintColor = UIColor.redColor()
}
答案 2 :(得分:1)
是的,您必须在项目中导入蓝色。在viewDidLoad()中,只需粘贴这些行。
目标C: -
[yourBtn setBackgroundImage:[UIImage imageNamed:@"whiteImage.png"] forState:UIControlStateNormal];
[yourBtn setBackgroundImage:[UIImage imageNamed:@"blueImage.png"] forState:UIControlStateSelected];
斯威夫特: -
yourBtn.setBackgroundImage(UIImage(named: "whiteImage.png"), forState: .Normal)
yourBtn.setBackgroundImage(UIImage(named: "blueImage.png"), forState: .Selected)
为此按钮创建操作,只需粘贴此代码即可。
目标C: -
-(void)buttonTapped:(UIButton *)sender
{
if(sender.isSelected)
{
[sender setSelected:NO];
}
else
{
[sender setSelected:YES];
}
}
斯威夫特: -
func buttonTapped(sender: UIButton) {
if sender.isSelected {
sender.selected = false
}
else {
sender.selected = true
}
}
答案 3 :(得分:0)
试试这个: -
[self.yourBtn addTarget:self action:@selector(ButtonSelector:) forControlEvents:UIControlEventTouchUpInside];
[self.yourBtn setBackgroundImage:[UIImage imageNamed:@"whiteImage@2x.png"]forState:UIControlStateNormal];
-(void)ButtonSelector:(UIButton *)sender{
if ([sender isSelected]) {
[self.yourBtn setBackgroundImage:[UIImage imageNamed:@"whiteImage@2x.png"]forState:UIControlStateNormal];
[sender setSelected: NO];
} else {
[self.yourBtn setBackgroundImage:[UIImage imageNamed:@"blueImage@2x.png"]forState:UIControlStateNormal];
[sender setSelected: YES];
}
}