How to make partly transparent png-image buttons for iPhone? - iphone

My iPhone App has custom buttons that display png-images.
I like to replace the white color in those images by a transparent color. Is there a tool on the Mac that allows me to do that? (or is there some other way to indicate which color is transparent in xcode?)

The Preview application has a mode on its select tool called "Instant Alpha" which eases selection of backgrounds. Once you have your background selected, you can simply press the "Delete" key and that area of the image will be removed. Save it as a PNG with the "Alpha" box checked and you're done.
Most other image editing tools, particularly those supporting multiple layers in the image, will also properly support PNG alpha channels. These will likely be easier than using Preview, but they are all third-party and many cost money so you will need to make that decision.
Please note however that if you are starting from an image with a solid background to which some things have a faded edge that blends in to the background, it is unlikely that you'll be able to remove the background entirely to your satisfaction without cutting in to the actual image.
You may have seen GIF images in the past which were designed to blend in on a white background and had some bright pixels at the edges which stood out and look ugly on darker backgrounds. An image properly saved as PNG or any other format with an alpha channel from the beginning will not have this problem.

Just set the image view alpha.
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor=[UIColor greenColor]; //Set background color
UIImageView *imgView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:#"images-4.jpeg"]] ; // Create and initialize imageView
imgView.frame=CGRectMake(10, 10, 200,250);// Set frame for imageView
[self.view addSubview:imgView];
imgView.alpha=0.1; //Adjust alpha
}

Start with a png file (use image preview).
You have to go to View > Show Edit Toolbar.
Then widen the window so that you can see all of the icons.
Then click the icon that looks like a magic wand.
And then click and drag on the color you want to erase.

Related

How to add effects to UILabel

I've been searching for that many time ago and I can't find a solution. I have a animated label that crosses the screen of the iPhone (like the title of a song does in the Music app.Well, I'd like to add the "fade in/out" effect like the music app has. The easy solution is open Photoshop and create this simple image and then add it up to the label. Well, under the label I have an image with black backgroud. The image can be zoomed in and then the image with the fade in/out effect can be seen, and it doesn't look well. Is there any possibility to do this programatically? Thanks
PD: if there's another possibility rather than doing this programatically, I'll apreciate the answer as well.
Edit: Here's the image capture of the problem
I'll approach it in a non-programming way.
The image reference you gave us for the Music app you seem to be emulating has a different gradient than the one you drew in the second image.
If you notice in the image, the gradient has not fully completed its transition from clear to black before the words are cut off. I would say in photoshop run the gradient from clear to 80% alpha black and then draw a 100% alpha black rectangle to finish it off as per image. The white is just showing you what it looks like without the black background.
Now as for the zooming. Correct me if I am wrong, but it sounds like you want a viewing window for the image so that once you have zoomed into it, it will fade to either side, but still be viewable/movable in the center. This means that the image has to be zoom-able, but once you have zoomed the "fade in/out" should not be zoom-able.
Just make sure you aren't scaling the fader by keeping it separate from the scrollView of your background image.

transparent color to white for an UIImage

I realised that all my png images are defined with a transparent color instead of white color. I never noticed because the background of my app was white but now is of a different color. And as I cannot edit each single png file to replace the transparent color to white, I am looking for a simple programmatic way of replacing on the fly the transparent color by a white color. How should I do this please?
Thanks for any help
Cheers,
geebee
If I understand what you're trying to do, I would suggest you add a white background to your UIImageViews.
self.myImageView.backgroundColor = [UIColor whiteColor];
I don't see why you can't just "edit each single png file"; it's a pretty much instant batch operation using GraphicConverter or ImageMagick or whatever.
If you really insist on compensating for this on the device when the image loads, then just draw the image onto a white opaque rectangle and use the resulting composite image.

Create adjusted image similar to UIButton's adjustsImageWhenHighlighted effect

I'm working with some data icons in table view. And sometimes my icons is in disabled state. I want to try create grayed versions of my icons programmatically, before I ask designer to do that for me.
Similar adjustment happens in UIButton when image auto-adjusted for highlighted state. Does anyone know how to do that image adjustment?
What about just modifying the alpha of the icons?
If you make the images partly transparent you'll get a similar effect and no extra programming is needed.
Another possibility is to add a partially transparent gray UIImageView over the button. The button will essentially be made gray-looking -- you'll need the UIImageView to have an alpha of about .2, or somewhere in that range.

Free bitmaps for iOS custom buttons and sliders?

First, I'm not talking about icon libraries or mockup tools/libraries.
I'm familiar with various icon libraries that people have created, but other than the stuff from the example code like UICatalog, I'm wondering if anyone knows of anyone who has created free libraries of custom button bitmaps (stretchable button images), slider handle/track bitmaps, etc Basically bitmaps to customize the look of standard controls for those controls (like buttons and sliders) that allow you to specify such bitmaps.
I'm also interested in any photoshop tutorials/templates on/for creating stretchable custom button images, bitmaps for slider parts, etc. (Afraid I'm not a huge PS god or anything.)
Anyone know of any resources like this for fancying up the standard controls?
I've been able to find several stretchable buttons by searching through my collections of sample code for: "stretchableImageWithLeftCapWidth"
From the Apple sample code, the UICatalog, BubbleLevel, iPhoneMultichannelMixerTest, avTouch, AQOffilineRenderTest, and TouchCells sample code all contain buttons with stretchable images.
Hope this helps!
Stretchable buttons is no problem - there's nothing special you need to do in Photoshop. Just make the image of the button stretchable and set the radius to that of any rounded corners you have on the button graphic.
Slider parts - I'm pretty sure you'd have to make your own UIControl from scratch.
To make a button in Photoshop, create a new file with transparent background, select the Shape tool, rectangle near the bottom of the tools, drag out a rectangle. Size doesn't matterâ„¢. For a rounded rectangle, click and hold the same tool, choose the rounded rect shape and set a corner radies (same radius as in stretchableImage later).
Double-click the layer right of the layer name to get the layer style popup. Check Color Overlay and set the color you want. Check Inner Bevel and make its size somewhere below half the height of the rectangle - I think 90 degrees for the Global Angle works well. A lower opacity and larger size makes the bevel look less chunky.
Ctrl-click (option-click) the graphics rectangle in your layer to select the button's outline. Deselect the bottom half of it by using the marquee tool (M) at the top of the tools. Select a light gray foreground color, nearly white. Create a new layer with the square icon under the layer list (Windows->Layers if not visible). Fill the selection of the new layer with the paint bucket, and drag down opacity for the layer until the 'matte laquer' effect of it looks right.
A simple button, but that's the gist of it.

Loupe Magnification with White Text & Clear Background on Iphone

You guys helped so much with my last question, I figured I'd give you a shot at another. I have written an app with a theme that uses a dark blue glassy background and white / gray text and labels. The textfields in my app have clearcolor backgrounds and white texts and everything shows up very well. My only concern is that when you hold down a touch in a text box to get the magnification loupe, of course the white text shows up on a white background... which you can not read. Anybody got any ideas on how to implement a usable loupe here?
Unfortunately, the only "public" way I know how to change the loupe background is by setting textField.backgroundColor
I assume that since you're setting your backgrounds as clearColor, the magnifier defaults to white background, so the only way is to set your backgroundColor as something not clear.
I'm also assuming that since you did mention that you set your backgrounds a clear, that having it not be clear is not an option. So two ways I can think up in my mind about how to get around this is:
Assuming that the magnification lopue gets its background color by calling the backgroundColor implementation (and not some other obscure private API method): override the backgroundColor method and return a solid color.
Create your own loupe (probably not feasible)
I figured out a simple work around that achieved the desired effect. I also went through the full process of making my own loupe but since there is clear documentation on making your own loupe (see kiyoshi's answer), and this other method is ridiculously simple, I decided to document it here. It is basically just faking the clear background so that the white text shows up in the loupe. The background I am using for the view looks like blue smoke on a darker blue background:
alt text http://img231.imageshack.us/img231/9835/beforestatex.jpg
I took a screenshot of the simulator with the textfield visible and a black background so it would show up better:
alt text http://img193.imageshack.us/img193/9023/blackfieldx.jpg
Then I took that screenshot and made it semi transparent in photoshop, and overlayed my original background image to find exactly where the textfield appeared on the background:
alt text http://img266.imageshack.us/img266/9493/transparencyfullscreenx.jpg
Then I copied the exact pixels that would be used as the background of the textfield into a new PNG and saved that and set it as the the background image:
alt text http://img41.imageshack.us/img41/3450/textboxback.png
forwardToField.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:#"textboxback.png"]];
Keep in mind that the image will be repeated as a pattern within the loupe... so if you don't want to see the edges, simply make sure your textfield is larger than the loupe height and width.
Before:
alt text http://img196.imageshack.us/img196/2672/beforex.jpg
After:
alt text http://img23.imageshack.us/img23/2182/afterxd.jpg
I hope this helps somebody out there!
Actually its pretty feasible to create your own loop. Haven't tried subitting to apple yet so don't know how they feel about it.
Basic idea is override touches, use a timer to see how long the user has been touching the screen. The loupe is just a UIView that grabs as an image the view behind it and magnifies it.
Check out this article from Craftymind here
The article has you cache the entire image behind which is definitely faster, for rendering the loupe, but if you have stuff (i.e. textFields) that are constantly changing I've been able to render the loope image real-time without too much of a performance hit.