Creating a tinted UIImage from given UIImage - ios

I have a image and want to create a black tinted image of same as shown below:
I have a view and a image view as it's subview. The alpha of Image view is 0.5 and its tint color to Black color. Also the background color of view was set to black color. Using this the second screenshot is generated and I want a similar output to a new UIImage.
PS: I need a new image which can stored or reused independent of background views etc.
Also I have tried following so check before reporting duplicate:
How would I tint an image programatically on the iPhone?
Overlaying a UIImage with a color?
Making a UIImageView grey
iPhone: How to Dynamically Color a UIImage
I've also tried getting image from a view but that does not help as I've more components in view not shows here.

iPhone - flattening a UIImageView and subviews to image = blank image might help you with your problem. The idea is to "render in context" a UIView object with 2 subviews (the image, and the black overlay view) to get an image. If you have more subviews which you do not want in the image, simple hide them when rendering.

Related

Desaturate colors in views below a UIView

Is it possible to set a backgrounds image such that the views drawn below it are desaturated, rather than just darkened or tinted via a normal alpha value.
I do not have the ability to alter the views below, so it must be contained to the UIView or layer.
Thanks!
Sure, just overlay the view with a screenshot (How Do I Take a Screen Shot of a UIView?) and desaturate (ios sdk desaturate image).
Then you can display other viewcontroller modally with transparent background to see-through your desaturated image (iOS: Modal ViewController with transparent background).

xcode 7.3 custom image is grayed out in storyboard

I added custom image to to assets.xcassets as 3x in xcode project. It shows fine.
Next, I added the iage to Tab Bar Item by selecting system item as custom and selected image as custom image. Also populated Bar Item image by selecting custom image.
In my storyboard, the image icon is completely grayed out in both the Tab Bar Item and Bar Item.
The image was created in Gimp as transparent image size scaled to 75x75
Can someone tell me how to fix this?
Like #luiyezheng said, this is caused by the image rendering mode.
A better way to apply the rendering mode to all items in your TabBar will be to put this code in your TabBarController viewDidLoad method:
for item in self.tabBar.items! {
item.image = item.image?.imageWithRenderingMode(.AlwaysOriginal)
item.selectedImage = item.selectedImage?.imageWithRenderingMode(.AlwaysOriginal)
}
After iOS7, you can set whether a UIImage render using tint color of current view with imageWithRenderingMode:
AlwaysOriginal
Always draw the original image, without treating it as a template.
AlwaysTemplate
Always draw the image as a template image, ignoring its color
information.
Automatic
Use the default rendering mode for the context where the image is
used.
So what you want is:
self.barItem.image = UIImage(named: "yourImage")?.imageWithRenderingMode(.AlwaysOriginal)
By set renderingMode to AlwaysOriginal, the UIImage will always draw the original image and won't apply the template. Then you can get what you want.
Good luck:-)

Setting gradient background color to LaunchScreen which will display a logo image at center

I have a requirement to set a Gradient background to the launch screen with a UIImageView in the center which shows the app logo . I tried having a view controller but I realised code will never be invoked.
I need some way to get behaviour as the code below does
self.view.backgroundColor = UIColor(patternImage: UIImage(named: "background.png")!)
I went through lot of answers about the same topic, most of the questions on gradient colour don't seem to have any additional requirements like showing another image other than the background .
I can hardcode the color in IB but i don't get the gradient.
You cannot run code or use any custom classes in the Launch Screen. Basically the launch screen can use an interface builder file and accommodate size classes / auto layout, but you cannot create a gradient in code like you have.
You'll have to supply a stretchable image, which contains enough data for it to be viable in all resolutions.
You can use 2 layers of UIImageView:
The first is large and contain the background gradient image, and a second layer of centered image (with transparent backgrount) of the logo.

Creating UIView with BG Image and then drawing on top

what I am trying to do is to have an image on which I then want to draw something by overriding the drawRect function. Essentially I am trying to create dice, where I use a background and then have the relevant dots drawn in depending on the number selected.
I created the dice dots in PaintCode paint-code and then exported that to use in Xcode (Swift).
I am creating a UIView on Storyboard that I then want to add a background image to and then draw the dots based on the number I pass it.
On it's own the drawing of the dots are working fine, but when I try and add an Image using a subview with UIImageView the image doesn't show up, the background of the UIView is white and even setting it to clearColor() doesn't work.
Any suggestions?

UIView background color and transparent png on top

I actually have something simple but I just can't work it out as I'm fairly new to the iOS SDK. So I have a backgroundcolor on an UIView. On top of that I would like to place an image covering the whole UIView as a kind of backgroundimage. The image I'm using is a png which contains transparent areas. I'd like to see the background color through this transparent areas. I do not want to set the transparency of the image itself.
I believe you can set the background color of your view to an image, but this solution should help you learn more about views:
From code (assuming you've added your image to your project):
UIImage *image = [UIImage imageNamed:#"imageFileName"];
UIImageView *imageView = [[UIImageView alloc] initWIthImage:image];
[backgroundView addSubview:imageView];
On storyboard, drag an image view onto your background view. You can configure the image view's frame and image in storyboard. Once you drag the image view into your scene pay attention to where it lands in the view hierarchy. You can choose how exactly you want to set this up, for example, do you want the image view to be a sibling of the background view and lay on top of it? or do you want the image view to be a child of the background view and take up the whole background view's bounds? Same thing as far as the user is concerned, just different organization under the hood.
If you create a transparent area in an image in ex Photoshop, and saving as PNG it will be transparent in Xcode. That's why I always use PNG images.

Resources