What I'm trying to achieve might be a bit of a novelty, but maybe someone has already done this or has some great ideas.
Here's the situation: I have a UITableView sitting on top of a UIImageView (which provides the background) that has a brushed metal texture. The fist row in the table is colored black. What I'd like to achieve, is the following: when the user tries to scroll up (by pulling down) from the top of the tableview and thus causes the "bounce" physics to kick in I'd like to have the space at the top of the table view be black to seamlessly blend rather than have the user see the background image.
I can't just add another black subview under the the table because then if the tables contents is just one row it'd show under the first cell as well, considering bounce scroll lets the user scroll halfway down the screen.
I've tried setting the cells background view to a black view with a rect like 0, -100, 320, 142 (where the cell itself should be 42px high) and setting clipsToBounds to NO on both the backgroundView and the cell itself, but no dice.
Any ideas?
Set UITableView.tableHeaderView to a suitable view. Headers/footers are useful in general (you can have shadows at the end like UIWebView, or a background that moves with the cells, or whatever).
Make sure you handle the zero-cells case sensibly (although the problem isn't visible if scrolling's disabled when there aren't enough cells to require it, or if there can't be zero cells).
Related
I ran into a strange situation when a UITableView is used within the context of a UINavigationController.
tvOS uses UIView.mask to apply a "fade-out gradient" at the top and bottom of a UITableView, so that cells fade into and out of existence at the top and bottom edges of the table view.
That's fine: the fading mask always stays out of the way of the selected cell.
(Here, view.backgroundColor is set to red and tableView.backgroundColor is set to blue with 50% alpha. The constraints of the tableView are set to the safe area.)
The problem comes when you put your view controller inside of a UINavigationController. When selection is near the top, the mask view no longer seems to avoid the cell, so it looks faded. Additionally, as the user scrolls down, the fading mask takes a giant jump downward, and then as the user starts to scroll back up, that fading mask doesn't seem to get out of the way:
For reference, here is the same setup but with tableView.mask = nil:
(All fading is disabled, but you can see the cells "pop" into and out of existence at the top and bottom of the tableview. You might think you could just set tableView.masksToBounds = true, but then the selected cell gets chopped off because it grows when selected)
Surely I'm missing something obvious here? Did no one at apple put a tableview inside of a nav controller?
You were so close! The clips to bounds was missing.
tableView.clipsToBounds = true
tableView.mask = nil
Cheers :)
I am creating an iPad view which has a tableview as a subview. The tableview only takes a small portion of the screen and is somewhere near the middle of the screen and it contains some menu items. I want people to be about to scroll this tableview up and down however I do not like how the cells disappear against a hard edge. When I set clipsToBounds to false, I get what I want in that the hard edge is not there anymore but the top/bottom cell disappears when the tableview needs that cell for recycling. Is there a common technique to avoid this hard-edge of when the cells scroll up against the tableview's bounds? I was thinking of adding gradient alpha masks on a parent container view but it seems a bit over the top.
There are no hard and fast rule about this, but you certainly can do whatever you feel best. What I would do in a case of floating tableView is giving it a nice border using layer. It is easy to code (2~3 lines). Round the edge to make it pretty.
If you want to drop shadow, it gets a little more complicated but possible. Just draw a bezier curve path of a rectangle (where you want your shadow to appear). Assign that CALayer shadowPath. Then add it to the table.
You can also gradient an alpha to make it appear shadow like.
But I would suggest, you set clipsToBounds to YES since it looks horrible otherwise, given the fact that the table 'floats' somewhere in your view.
I have a UIToolbar in IB with a custom UIBarButtonItem that is set to an image. The image height is larger than the UIToolbar height. The image does not load for some reason. Attached is a screenshot.
You should avoid using subviews that are larger than the parent view - even if it does work and draws the view outside of the bounds, you cannot always count on it because the clipping is skipped for performance reasons and depending on the drawing order the overlapping part of the subview might be covered later. Second problem is that only the part within the frame of the superview is able to handle the touch events.
As to why you don't see your image, it's probably a different problem, I doubt it has something to do with it going outside the frame. Post your code to get more feedback ;)
I am currently working on an application for a client, and they have made an odd request. The request involves putting a custom image as the indicator for the scrollview. I am not even sure if this is possible but if it is can you please let me know how one would go about doing that.
Thanks
UIScrollView streches a small, semi-transparent circle image to generate its scrollbars. You can find this image as the first subview of a UIScrollView:
UIImageView *circle = [scrollView.subviews objectAtIndex:0];
However, as I said this image is stretched, and as far as I can tell, only the alpha values are considered when drawing the scroll bars.
So for example if you're only interested in changing the top/bottom ends of the scroll bar, you can try to change this image. However, I doubt you'll be able to do anything interesting.
A possible solution that comes to mind, and this is only a theory, is to add a custom, transparent UIView on top of a UIScrollView. Then you can hide the default scroll bar (by using showsHorizontalScrollIndicator and showsVerticalScrollIndicator), pass the necessary touch events to the UIScrollView to scroll the content, and draw the scrollbars in your custom view.
I want to display a handle at the corners of a UIView that can be used to resize the view. How can I display the handles floating on the top of everything else and still have a connection to and be in sync with a view?
The solution I implemented before looks like this:
alt text http://bayimg.com/image/dalipaacn.jpg
I put the view into another view that shows the handles on top of the corners. The problem with this approach is that the handles add extra space to the original view's size. Since Apple recommends at least 40 x 40 px for the size of a button, it is not very little space and also goes beyond the visible bounds of the original view. Also when I want to align the original views border with its superviews border, parts of the handle buttons become untouchable. Another problem is that the original view has to be encapsulated in this 'helper view' object and thus becomes a part of something although it really is the main component.
You could make your frame view larger than the actual content, and then inset the content. That's probably the simplest way. You could also use views that weren't subviews of the frame view, but then you run into problems of synchronizing the handle with the content view, as you mentioned. I'd recommend the first option.