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];
Related
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)
u build an UIView and put an image as the view backgrond:
self.tmpView = [[UIView alloc] initWithFrame:CGRectMake(20, 70, 280, 295)];
self.tmpView.backgroundColor = [UIColor yellowColor];
self.tmpView.backgroundColor = [UIColor clearColor];
self.tmpView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"CloseUPPicBG.png"]];
the problem is that theuiview is now with corners in black color.
the image that i put as backgrond is with rounded corners.
any solution for this?
Edit the image to not have rounded corners, or so that the space behind the corners is some other color or image.
What you're doing is saying
View, be yellow.
View, be clear. What's behind you? Nothing. Ok, be black.
View, fill yourself with this image.
View is then thinking
Hmm... there's transparency in this image.
Guess I should show whatever's behind me. Which is nothing... So black.
self.tmpView.opaque = NO;
might help.
can I change the background image of my TTThumbsViewController. It's the thumbnail overview screen and at the moment it is white. Can I turn it to transparent?
Thx :-)
(void)viewDidLoad {
self.tableView.backgroundColor = [UIColor blackColor];
}
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.
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