UILabel alpha causes text to fade as well - iphone

Is there a way such that I can set the alpha of a UILabel, but it doesn't fade out the text of the UILabel? Meaning just the background?

As the text is a part of the label, if you set the alpha for the label the text fades appropriately. What you want is to set a backgroundColor with the appropriate alpha:
myLabel.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:0.5];

You may have to create a background view (UIView will suffice), and put the UILabel on top (not as a subview, because the alpha value of the background view affects all of its subviews)

Related

how to change text color on focus a cell?

I am working on a app and i have a main table view. By default in iPhone if a cell is on focus its font color changes to white. I used this code to set the font of my cell:
lblTemp.font = [UIFont boldSystemFontOfSize:18];
lblTemp.backgroundColor = [UIColor clearColor];
When a cell is on focus its text color doesn't change to white. it remains black. how can i change a text's color oc a cell to white when its on focus. Thanx
Try to set highlightedTextColor property to your label:
lblTemp.highlightedTextColor = [UIColor whiteColor];

Clear Background color on UIImageView?

hello i have a UIimageView with a PNG image that has round corners, image sits fine the only problem it has is that i can see the UIImage Corners with a white background, how can I make the background clear and transparent.
Try this:
imageView.backgroundColor = [UIColor clearColor];
imageView.opaque = NO;
You can achieve the same thing in IB by making the 'Background' a color with 0% opacity, and unticking the 'Opaque' checkbox.
try
imageView.backgroundColor = [UIColor clearColor];

iPhone Subview Transparent

I subclassed a subview and added it to the current view. It draws a simple circle by overriding the draw method.
But the subview has a black background it looks like by default. How do I make the background of my subclassed subview to be transparent?
does
self.backgroundColor = [UIColor clearColor] not work?
You can call next code into view initialization:
self.backgroundColor = [UIColor clearColor];

iPhone SDK: Transparent tableviewcell isn't transparent?

I have a UITableViewController that has a background image. I am setting the image for the tableview like this:
[self.view setBackgroundColor: [UIColor colorWithPatternImage:
[UIImage imageWithContentsOfFile:
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:
#"background1.jpg"]]]];
The problem is, each of my custom tableview cells get the same background image--it's repeated in each cell. As a test, I tried making everything in my cell transparent with an alpha of 0.0, but even then although I can't see any of the labels in each cell, I still see the background image repeated in each cell:
cell.backgroundColor = [UIColor clearColor];
cell.contentView.backgroundColor = [UIColor clearColor];
cell.contentView.alpha = 0.0;
cell.alpha = 0.0;
Any suggestions on how to get my table's background image to stop repeating in each cell would be appreciated!
Have you tried setting the opaque property to NO? It's defined in NSView.
[cell setOpaque:NO];
It's defined in the Apple API as follows:
YES if it is opaque; otherwise, NO. If
opaque, the drawing operation assumes
that the view fills its bounds and can
draw more efficiently. The results are
unpredictable if opaque and the view
doesn’t fill its bounds. Set this
property to NO if the view is fully or
partially transparent. The default
value is YES.

How to retain or animate subview background color in UITableViewCell on selection?

I have a UIView as a subview of a custom subclass of UITableViewCell. I'm using it to change the color of just a small area of the cell dynamically.
When I select the cell, the background color of the entire cell -- including the background color of the subview -- is changed to blue. That's fine, it happens instantaneously. Selection drills down to another view controller.
However, when I come back from the view controller, it animates the background again from blue to white -- but it doesn't animate the background color of my subview. The effect is blue animated to white, then abruptly changing back to my original color.
How do I either
exempt this subview's background color from changing at all,
or animate the transition so that my color gets returned nicely?
Thanks!
The following shows how to animate a colour change:
UIView * blue = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 300, 20)];
[self.view addSubview:blue];
blue.backgroundColor = [UIColor whiteColor];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
blue.backgroundColor = [UIColor blueColor];
[UIView commitAnimations];
[blue release];
Hopefully, you can adapt it to suit your needs.
Tom