My sprite image is black, I want to change this color to whatever I want.
The code I'm using:
var sprite = SKSpriteNode(imageNamed: "layer1-0\(random(1..<4))")
ceilingPieces.append(sprite)
sprite.setScale(0.5)
sprite.position = CGPointMake(900, 335)
sprite.color = UIColor.purpleColor()
sprite.colorBlendFactor = 1.0
self.addChild(sprite)
The image stays black, but I want it to be purple.
Thanks!
Toby.
A black tile image isn't going to be able to tint. You're working with filters here so it doesn't matter what you put over it, it's still going to look black. Get a white or mostly white image and you'll see that it will work as expected. Again, tint color is multiplied by the original color to get to the end result.
If you were instead working with
var sprite = SKSpriteNode(color: UIColor.blackColor(), size: CGSizeMake(100, 100))
you could then change the color but it would be a blend, it would simply be changing the color with
sprite.color = UIColor.purpleColor()
Related
I have this screen with an UIImageView (the image is a SF Symbol)
The user can see this icon clearly, white on black. But - if the background is different:
It may be hard to see it.
I want to add a black shadow to the image so the user can see it better.
I tried looking online but all I saw is how to add shadow to the image view box, and that is not what I need. I need the shadow around the icon itself and not around the box of the image.
Any ideas? thanks in advance
Try this:
imageView.layer.shadowColor = UIColor.black.cgColor
imageView.layer.shadowRadius = 3.0
imageView.layer.shadowOpacity = 1.0
imageView.layer.shadowOffset = CGSize(width: 4, height: 4)
imageView.layer.masksToBounds = false
I'm trying to apply an "under circle mask" for a png image with transparency.
I tried:
var image = UIImage(named: "logo")!
image = image.imageWithRenderingMode(.AlwaysTemplate)
self.imageViewLogo.tintColor = UIColor.redColor()
self.imageViewLogo.image = image
If my logo is a transparent image with a cat black inside, this code produce the same image but with a red cat.
My purpose is to obtain the black cat with the red background color.
How can I achieve this without lack of performance?
Using this...
image = image.imageWithRenderingMode(.AlwaysTemplate)
Will use the non-transparent parts of the image as a template for how much of the tint color to apply.
What you want to do is just use the standard image and set the background color of the image view.
let image = UIImage(named: "logo")!
imageViewLogo.image = image
imageViewLogo.backgroundColor = UIColor.redColor()
For rounded corners of the view so that it is in a circle you can add the following...
imageViewLogo.layer.cornerRadius = CGRectGetHeight(imageView.frame) * 0.5
imageViewLogo.clipsToBounds = true
That will round the corners with a radius of half the height and then clip the edges to the rounded corners.
Simply set background color of an image view
imageView.tintColor = UIColor.blackColor()
imageView.backgroundColor = UIColor.redColor()
If you want to just use your image (image is black), you don't even need tintColor for image view and just set rendering mode of image to .AlwaysOriginal
I was hoping to make my UIImage "highlight" briefly upon being tapped. Not sure of the color yet, but let's say blue for arguments sake. So you tap the image, it briefly looks blue and then it navigates you to a details page to edit something on another screen.
From some initial reading it seems the right course of action is to use the Quartz framework and do this:
imageView.layer.backgroundColor = UIColor.blueColor()
imageView.layer.opacity = 0.7
I guess the idea would be you change the background of the layer behind the image, and then by setting the opacity of the image, the blue "bleeds through" a little bit, giving you a slightly blue image?
When I try the above, however, a blue border goes around the image itself, and based upon the opacity, the blue is either dark or light. The actual image does not become any more blue, but it does react to the opacity (meaning if I set it to something like .1, the image is very faded and barely visible). Why does the image react correctly, but not show blue?
Thanks so much!
As far as I know changing the opacity will change the opacity for the WHOLE view, meaning not just the UIImage that the UIImageView holds. So instead of fading to reveal the UIImageView's background color, instead the opacity of the whole view is just decreased as you're seeing.
Another way you could do it though would be to add an initially transparent UIView on top of your UIImageView and change its opacity instead:
UIView *blueCover = [[UIView alloc] initWithFrame: myImageView.frame];
blueCover.backgroundColor = [UIColor blueColor];
blueCover.layer.opacity = 0.0f;
[self.view addSubview: blueCover];
[UIView animateWithDuration:0.2f animations^{
blueCover.layer.opacity = 0.5f
}];
Here's how I use tint and tint opacities in IOS 9 with Swift -
//apply a color to an image
//ref - http://stackoverflow.com/questions/28427935/how-can-i-change-image-tintcolor
//ref - https://www.captechconsulting.com/blogs/ios-7-tutorial-series-tint-color-and-easy-app-theming
func getTintedImage() -> UIImageView {
var image : UIImage
var imageView : UIImageView
image = UIImage(named: "someAsset")!
let size : CGSize = image.size
let frame : CGRect = CGRectMake((UIScreen.mainScreen().bounds.width-86)/2, 600, size.width, size.height)
let redCover : UIView = UIView(frame: frame)
redCover.backgroundColor = UIColor.redColor()
redCover.layer.opacity = 0.75
imageView = UIImageView()
imageView.image = image.imageWithRenderingMode(UIImageRenderingMode.Automatic)
imageView.addSubview(redCover)
return imageView
}
Is this tap highlight perhaps something you could do with a UIButton? UIButton has all these states off the bat and might be a bit easier to work with, specially if there's something that actually needs to happen after you tap it. Worst case scenario is you have a UIButton that does not trigger any method when tapped.
You can try changing the tint color instead:
UIImage *image = [UIImage imageNamed:#"yourImageAsset"];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
imageView.tintColor = [UIColor blueColor];
imageView.image = image;
I've scoured the web and haven't found a way to customize the color of the blue pulsing ring around the user's location on a map.
Does anyone know a way to customize the color of the pulsing ring?
The blue color for the user location is based on the tint color of your map view, changing this will set the new color for the user location circle.
//Objective-C
mapView.tintColor = [UIColor redColor];
//Swift 4.2
mapView.tintColor = UIColor.red
In Swift 3
mapView.tintColor = UIColor.red
or use Color Literal
I have a sprite and I set its color and then I want to set it back to the old color(Default color) how can I do it
here a simple code
sprite = [[CCSprite alloc] initWithFile:#"zero.png"];
sprite.color = ccc3(255, 223, 0);
....
How to set it back to the default color
sprite.color = ???????
or I have to find out the default color by find that old color RGB code?
sprite.color = ccWHITE;
And I have to add some text here so SO will accept the answer. :)
ccWHITE is the same as ccc3(255, 255, 255)