Layering UIViews so that bottom most layer can be seen - iphone

I have a UIView to which i add a background image. Then to that view i add a scroll view. To the scroll view i add some UIButtons.
I would like to be able to set the scroll view to be transparent (still being able to see the UIButtons) so that i can see the background image underneath it, so that it shows between the buttons.
I have tried setting the scrollview background to [UIColor clearColor] but this doesnt work.
Thanks.

In addition to setting the backgroundColor to [UIColor clearColor], you also have to set
scrollView.opaque = NO;

Change the UIScrollView.alpha level to 0.0f

Related

UINavigationController - Keep Background Image Across All Views

Is there a way to have a background image remain constant across all views in a navigation controller? Currently I am loading the same background in each view's viewDidLoad method but this shows the background image move when navigating from view to view. I'd rather just the content of the view infront of the background "slide" on/off screen, but the background stay stationary. This is my current background image loading code:
UIImageView *background = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
background.image = [UIImage imageNamed:#"InfoBackground.png"];
[self.view addSubview:background];
[self.view sendSubviewToBack:background];
[background release];
Thanks!
Hm, perhaps if you look at the documentation (scroll down to Figure 2) you will get an idea of what you're dealing with. Because you are setting the background image for each of your view controllers that are being pushed into the UINavigationController, you will get that animation. What you need to do is set the background image into the nav controller itself.
I believe myNavController.view insertSubview:myImageView atIndex:0 should work. If your image needs to fill in behind the content view exactly, you could set the frame coordinates based on the coordinates and/or heights of the navbar and toolbar, which can be accessed through the navigation controller's properties. If not, just set the frame to the superview's bounds.
Let me know how it goes.
Edit: Oh, note that you would need to make sure each of your view controllers had transparent backgrounds.
i think the better idea is place background image on window and set all view's(all viewcontroller's view) background color to clear color [UIColor clearColor].
if you want background image static then there is only one way but i don't know that is possible or not, If we put image in window and make navigation controller transparent then it's stay static whatever you will do. because we are not changing window while push or pop.
I am just suggesting try this way i haven't tried like this.

UITapGestureRecognizer on transparent view

I have a tree with views where the highest level view is transparent and contains either an image or a label (with a transparent background).
When attaching a UITapGestureRecognizer to this view, I only get notifications on the views which contain images.Also, if I leave the view empty, then I get events only when the background color is different than [UIColor clearColor].
I have done a dump and the entire view tree has userInteractionEnable = YES.
How can I get the UITapGesturerRecognizer to work on the view with a transparent background?
Solved
Problem was not what I thought. The transparent views were in a scroll view and during initialization they were outside of the view's visible area. Those within the visible area work ok.
Wild guesses here, but if you include a 1x1 pixel image in the view, would that view then qualify for gestures?
Another equally wild guess would be to add a transparent image to the view and try that.
Try giving the view a nearly-transparent background color, like [UIColor colorWithWhite:0 alpha:0.01].
Try setting the background color to whatever except the clearColor and setting the alpha property to 0.0;
myView.backgroundColor = [UIColor blackColor];
myView.alpha = 0.0;

Black corners around UITableViewCells

I am trying to display a UITableView in front of an image, and here's the steps I'm following:
Inside the view, add a UIImageView with the image set to the appropriate file in the project
Add a UITableView inside the parent view (the same parent as the image view)
Set the backgroundColor for the table view to clear
Wire up a datasource in the view controller to display some test data
Hook up the data source in IB.
After doing this, the tableviewcells have a black background in the corners. It isn't coming from any of the parent views as far as I can tell. I have a test project at bitbucket which demonstrates the issue.
Jeff Lamarche ran into the exact same issue today and put up a blog post about it:
http://iphonedevelopment.blogspot.com/2010/08/transparent-grouped-tableviews.html
Basically, there appears to be some bug where you still need to add this in code (even though you already have the tableView set to be clear in Interface Builder):
self.tableView.backgroundColor = [UIColor clearColor];
To remove the black edges just go to ur .m file and in ur viewDidLoad method add a line
tableName.backgroundColor = [UIColor clearColor];
and thats it no more ugly UI
As stated in Jawboxer's answer, you need to set the background colour in code:
self.tableView.backgroundColor = [UIColor clearColor];
But also ensure that the background colour in Interface Builder is set to the default "Group Table View Background Color". I had it as "Clear Color" in IB and it still wasn't working, until I reset it to the default.
The root cause of why you must set the clear color in code is here: Black corners on UITableView Group Style

Is there a way to fix the background image of a UITableView

I have set the background of my UITable with a custom image.
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"background.png"]];
The problem I'm having is the background image is scrolling and doesn't look good at the top and bottom of the screen where you see the image being joined.
Is there a way to fix the position of the background image and just have the table scroll over the top of it?
Insert a UIImageView behind the UITableView. Set the UIImageView's image to background.png. Use [UIColor clearColor] as the table's background.
You need to put a UIImageView beneath your table view, set the table view's background color to clear (or in IB, set the opacity property of its background at 0). Then construct your CELL views to have clear areas that your background image can be seen through. You can do that programmatically or in IB (it's easier to visualize in IB, but the code to hook it all together is a bit tricky).

Black corners on UITableView Group Style

I have a problem where my UITableView (group style) has a black "tip" above it's rounded corner.
I'm setting up the background of the tableview like so:
[meetingTableView setBackgroundColor:[[UIColor alloc] initWithPatternImage:[[UIImage alloc] initWithContentsOfFile:#"background.png"]]];
And my table view ends up looking like this:
black pointy edge on rounded corner http://papernapkin.org/pastebin/resource/images/imageEntryId/6487
Any ideas how I can get rid of those black points?
I have got the same problem.
When I set clear color by xib, I have the back corner
The solution is to set it by code !
(The same problem with interface builder exist for webviews)
Try this in your controller's viewDidLoad method:
meetingTableView.backgroundColor = [UIColor clearColor];
You'll get Black corners on UITableView Group Style if you set background color to clear color in XIB.
Instead try this code for removing Black corners on UITableView Group Style
tableViewObject.backgroundColor=[UIColor clearColor];
Just in case you weren't already aware, there's another neat technique you can use to make customized backgrounds for UITableViews:
Not quite as simple as setting the background as you're doing, but it gives you a lot more flexibility and can scale to any table size.
Maybe if you put yourTableViewOutlet.backgroundView=nil;
To avoid the black corners you have to make sure that the UITableViewCells are not opaque. It looks like you're using custom styles table cells and the default value for opaque is YES. Either go to Interface Builder and uncheck the opaque checkbox if the table cell was set up in a XIB file. Or use the setOpaque:NO setter to change value.
Because the table cell view still has a rectangular frame even with the rounded corners the cell view and not the actual table view is causing those black corners.
My guess is that it's related to something that you're doing in your custom table view cells. You might want to experiment with setting the cell background color to [UIColor clearColor].
I think you should set the background color of your table as clearColor and initialsie your view with the background image.
Then it will definitely not show the black corners. But also don't forget to set the background color of your cell as white color
The up-voted answer above (set the tableView's background to [UIColor clearColor]) may not work for you if you are like me and never use the UITableViewController, instead putting a UITableView inside a UIViewController.
In this case it's not the tableView that needs to have a clear background, but the view that holds the tableview.
This is not intuitive, but it works for me. In interface builder you can just set the parent view's background color to clear color, or you could do the same in code in viewDidLoad with:
self.view.backgroundColor = [UIColor clearColor];
I'm guessing the reason for the black corners is something about the internal graphics optimization, and setting the background clear fixes it.