Problem to set a custom image to TabBarItem [duplicate] - ios

This question already has answers here:
How can I remove the blue square that overlays UITabBarItem when selected?
(3 answers)
Closed 4 years ago.
I've a image 30x30 and I want set like TabBarItem in my TabBar. But when I set the result is this:
The large blue square appears instead my image.

Did you check your image file name? Becuase I had exactly same experience and it was imge file name did not match with the name I put on storyboard

Make sure your image is single-color, preferably black and white. If there's a background, even one with a low alpha, you may get this effect. The OS is trying to make an iOS-style tab bar image (think of the ones in the Music app), which is single color. It converts the non-transparent pixels to blue, and the transparent ones to white/clear. If the entire image is non-transparent, you'll end up with that.

Related

tab bar icons appear as blue squares

Well, the title says most of it. I've tried with icon sets of 75/50/25 px and 72/48/24 px, as stated by different guides, but when I run the app in Xcode, the icons appear as (appropriately sized) blue squares. The icons are all black and white .png files, with negative images for the selected images. Any suggestions would be appreciated.
This might not fix your issue, and also may seem very obvious. But I'll put it here just in case it helps anyone.
First of all, I'm going to point out scenarios to check that can get you in this state that may or may not apply to everyone:
The asset's render type is set to Template Image
You are changing the tabBar.tintColor
If either of these are true and you are getting a solid colored square as your icon, the first thing I would check is the actual image you are using. It is probably an image/icon sitting on a white background or something like that rather than a transparent background.
If you are using a .png, .pdf, or .svg icon and want to tint the icon, you will need a transparent background. Transparency doesn't exist for .jpegs so they just won't work for tinting the icons.
This is because changing the tint will tint the whole image. If there isn't transparency, Xcode will have no idea what is icon and what is background. So a 40x40 icon just becomes a colored square.
Another benefit of using a transparent background will be now instead of having multiple images for selected/unselected states, you can just set the desired colors for .selected and .normal states and use one image.
Okay, the solution is NOT to set the image to render as image, but to use an alpha 0 background instead of a white background on the icon image.
Another tip. Don't name your image assets the same name as iOS System icons/glyphs. I had a download icon labeled download(.png). After renaming the issue disappeared. Very inconsistent behavior.

Importing a Sketch Image into Xcode (Using UIBarButtonItem) [duplicate]

This question already has an answer here:
UIBarButtonItem showing up as a blue square instead of the image I want (Interface Editor)
(1 answer)
Closed 6 years ago.
I am trying to put a Sketch image into a UIBarBuuttonItem. The image has a transparent background and the image is a camera that is blue with a white circle inside. I am sure I'm exporting the entire image. I am using a 1x, 2x, and 3x version of the image and when I set the image of a UIBarButtonItem in the storyboard, it only shows the blue part of the camera and not the white circle inside. If I put a UIImage in a ViewController and set it to the same image, the image shows up correctly. The image shows the difference. Thanks in advance]1
In your image in xcasset, try change it's render to Original image in attribute inspector, maybe the issue is the tint color

Stretch image border uniformly and leave center of image unstretched on iOS

Is it possible to achieve the same thing on iOS as on Android with this 9-patch file?
Result should be something like this. The flower is something on the background. Then I want to apply the gray overlay with transparent (see through, not stretched) logo in the center.
(the file is not a valid 9-patch, because of wider patch areas, but that is only for question clarity)
So basically I'd like to overlay the screen with this semi-transparent gray color and in the center would be unstretched logo - kind of cut-off from the overlay. (Notice that logo in image is completely transparent)
I tried to use image slices, but I can't define multiple slices per dimension, so just one border is resizing.
I'd like to avoid tile-ing the background from multiple views.

Toolbar button image suppressed

I have a viewcontroller with a toolbar with 2 bar button items. The image on one is a simple flat icon. The other is a complex image reduced to 28x28 pixels from a 256x256 image. The complex image shows up as a blob as shown below. The actual image is also show in the picture. It is not clear what I am doing wrong. The project code is available in the following link:
Project code
John Griffith on Apple Developer Forum provided this explanation which made a lot of sense. I need to redesign my icons if I want to proceed along this line:
Toolbar images are normally rendering mode "template" - only the alpha channel is used. Any non-transparent pixels are drawn in the bar's tint color. It may be possible to create a UIImage with rendering mode "always original" to preserve the look of your image, but then it won't respond to changes in tint color.
I have downloaded your project. The first thing you should do is to move your image files into the images.xcassets folder. Read here to understand why.
The image you are trying to display is actually just a red rectangle:
As you can see, opening in another program also just displays it as a red rectangle. Be sure to use the correct Image file. The problem lies not with your project but rather the image file you are using.

Highlight(Overlay) specific area on UIImage

I am developing a book app. Book pages are images. At a time one image is shown on iphone screen. Image contains lines(Paragraphs). I want to highlight the whole paragraph on touch on that. Is it possible to highlight the paragraph or make overlay on the whole paragraph or change the color of that paragraph. Any Help please?
As your book page is an image, the only way you can do it is to either change the image or add a view on top with a color and an alpha value. With the latter you also overlay the letters of course, so the effect will kind of blurry your text.
Next to that, recognising the paragraph won't be trivial, depending on your image quality. The same counts for changing the image - if your background is not a clean color you have to introduce some threshold for which color is the background color and should be changed to the highlight color.
For how to change the color of specific pixels in an UIImage see here:
iPhone : How to change color of particular pixel of a UIImage?

Resources