UITableView Stacked/Shadow Background - iphone

I'm trying to make a UITableView look as though it's on top of a stack of papers. I did a similar version of this using UIView by overriding drawRect, but with UITableView's complexity, I believe it will be more involved than it was with a standard UIView. If I use a stretchable image, the stretched bits won't line up. What would be the best way of achieving something like this?

For Shadow, you can use the CALayer, as in the example below.
tableView.layer.shadowRadius = 3.f;
tableView.layer.shadowColor = [UIColor blackColor].CGColor;
tableView.layer.shadowOffset = CGSizeMake(2, 2);
tableView.layer.shadowOpacity = .6f;
For the stack impression, i would add some views with same shadow borders beneath the table view.

Related

Creating a shadow view

I have a UIView set as "shadow", and I put this view behind a UIImageView to create a shadow effect. The only problem is, if you decrease the alpha of the image, you can see the white part of the UIView. How do I hide the whole UIView except for the shadow? Setting the backgroundColor to clearColor hides both the view and the shadow, which doesn't help. Thanks.
shadow.alpha = 0.95;
shadow.layer.cornerRadius = 10;
shadow.layer.shadowColor = [UIColor blackColor].CGColor;
shadow.layer.shadowOpacity = 1.0;
shadow.layer.shadowRadius = 10.0;
shadow.layer.shadowOffset = CGSizeMake(0, 4);
Have you tried modifying the UIImageView's layer to have the shadow, rather than having two views?
If that doesn't give the desired output, does a black UIView work? If you post a screenshot and the desired effect, maybe I can be of more assistance.
I don't think it's possible to do what you're attempting using the built-in shadow facilities. As you've discovered, there has to be something drawn in order for Quartz to have an outline to automatically shadow. (In this case, it's the background roundrect of the view.)
If you specify an explicit roundrect shadowPath for the shadow view's layer, that will do away with the need for the view to actually draw anything. However, the shadow itself appears to be constructed by filling the shadow path and then blurring and translating the resulting image, so you'll end up with essentially the same effect of a black background for the view.
I agree with Ryan Oksenhorn that you'd be better off working with the image view itself. If you add a shadow there, its opacity will drop with the view's, but that's probably all for the better. Do you really want to fade the image and leave a disembodied shadow behind?
How about you set
shadow.backgroundColor = [UIColor blackColor];
shadow.alpha = 1.0;

iPhone: TableView separator

I know that iPhone SDK can set a color to the TableView separator like this:
myTableView.style = UITableViewStylePlain;
myTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
myTableView.separatorColor = [UIColor blackColor];
Is there any way to set gradient color to separator ? Thanks...
You can make the separator style UITableViewCellSeparatorStyleNone and apply a one point wide line to the bottom of each cell, which is a gradient.
The only problem is that it might look odd on tableviews with fewer cells than fit on the screen when the table view has a plain style, but I don't know how to fix that.
You could draw your TableViewCells (see Loren Brichter's fast scrolling) and then add gradient drawing to your drawContentView: implementation. For details on gradient drawing, see the "Drawing with a gradient" section of the CGContext documentation.
A great side effect of this is that your tableview scrolling becomes crazy fast... but you have to draw your cells, which can get complex if your cells have very complicated view hierarchies (which you should avoid anyway).

Change grouped UITableview border size

I know how to add a border to the tableview using:
myTableview.layer.borderColor = [UIColor redColor].CGColor
myTableview.layer.borderWidth = 3.0f;
Setting the border like this results in a square border around the bounds of the tableview not the bounds of the grouped cells in the tableview. Using a similar idea on the cells makes a square border around the bounds of the cell but not the rounded edges.
There doesnt seem to be any way of changing the seperator width on the cells either. Is it possible to make a border around a grouped tableview?
I'm not sure what you're asking. There is a cornerRadius property on CALayer in iOS 3.0 and later.
To use .layer, make sure you #import <QuartzCore/QuartzCore.h>. But UITableView does not have the border properties you are looking for, so unfortunately your code will not work.
You can however either place the UITableView on a UIImageView with an image that has a border which would be the easiest solution, or you can use CoreGraphics to draw out the border which would be a lot more work.
Thanks for the above, but Ive decided in the end to go with this method for customizing grouped tables:
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
Not as programmatic as I would have liked but it does the job brilliantly. Would like to think that this will be something Apple will make easier to implement in future XCode updates.

grouped table view with Loren Brichter's fast scroll

I'm using Loren Brichter's tweetie fast scroll where he draws out the entire cell in draw rect. When I set the table view style to grouped, the cell gets the right inset but does not get a rounded corner. Is there a preferred method to get a rounder corner cell using Brichter's fast scroll?
If it's just one line per section you could add something like
self.layer.cornerRadius = 10;
to your initWithFrame: (or something similar) of your cellView.
It's more difficult if you need only some of the corners do be round. But this question has been answered a couple of times. You could use the code from the following question in your drawRect:
Rounded UIView using CALayers - only some corners - How?

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.