I've got a UITableView which is shown in a UIView - the reason I've done this is that I want to place a solid rectangle over the table (with CGContextSetBlendMode kCGBlendModeMultiply) and continuously change its colour, so I get the effect of the table's text continuously changing colour. I can't think of any other way of doing this, but the problem I have is that the coloured rectangle always appears below the table and sits solidly on top of (or below if I change the order of the subviews) the other UIViews. It doesn't seem to have any effect on the table no matter what I do. Is there any way of changing the display order within the UIView? The table is connected from IB. I'm not sure what other info I need to post for anyone who might be able to answer! Thanks very much for any help.
In order to cover your TableView with another UIView, the covering UIView must have a sibling relationship with the TableView or with one of the ancestors of the TableView. If the TableView is "shown in a UIView", that UIView that it's shown in can never obscure the TableView. Child views always obscure parent views. Create another UIView inside the "shown in UIView", it will then be a sibling view to the TableView, and can be put on top of it. Like this:
UIView *parentView = [[UIView alloc] initWithFrame:parentFrame];
UITableView *tableView = [[UITableView alloc] // table create parameters....
[parentView addSubiew:tableView];
UIView *obscuringView = [[UIView alloc] initwithObscuringFrame];
[parentView addSubView:obscuringView];
The obscuring view will then sit on top of the table view.
Related
I'm looking at the Alarm Clock app on the iPhone and I see that when they are using custom graphics for their UITableViewCells for the gray gradient, and when there are no cells in the table, there is a background that looks like similar to the grouped table view cells background with a label that says No Alarms.
How can I achieve this effect? Currently in my view controller, I have the viewController's view, a label for "No Alarms" and the tableView. When I have zero alarms in the table, I just show the label, and hide the table, and vice vsa when there are alarms. The problem I'm getting is the graphics.
As a test, if I change the background color of the table to bright orange, that orange shines through to my tableViewCells. The tableViewCells and the tableView are both set to the default white, not clearColor and yet the viewController's view shines through. What am I missing? Thanks.
Set the View's background to "Group Table Background color" using XIB file. We can set the same background image to our view.
You need to make sure that the "No Alarms" label is the topmost subview in your view's hierarchy. If it is, then you shouldn't have to worry about hiding your table view and won't have to deal with the problems you are having with the orange/white backgrounds.
Programatically, adding a label to the top level view would look something like:
UILabel *label = [[UILabel alloc] init];
label.text = #"No Alarms";
// set the properties, autoresizing, etc...
[label sizeToFit];
[self.view addSubview:label];
The last line is what actually adds the label to your view. If you want to have the label centered in the view you want to maybe use initWithFrame: as opposed to just init that way you can have it in the center of the view.
Another option (if you are using a NIB or storyboards) is to just create a "No Alarms" label and make sure it is the topmost subview in the view's subview hierarchy on the IB item explorer (I think that's what it's called at least - either way I'm referring to the flyout menu where you can select the objects in your view). Then just hide and unhide the label when your program logic says there are and aren't alarms. This is the way I'd probably do it...
I'm trying to create a paginated UIScrollView within a view that only scrolls horizontally and is populated by labels.
There are 4 labels and each label shows a string derived from a NSDate, with each one being linked to a PageControl to show which page the user is on.
I'm having a little trouble trying to figure this out based on sample code and other answers.
If I've already dragged out the dimensions on IB, do I still need to specify the frame and such?
Do I then have to create views with labels on them? Or can I simply create labels and populate the UIScrollView?
Is there any way to get the background of the UIScrollView transparent?
You can add UILabels directly to the scroll view as they are a subclass of UIView. If you have already specified the size and position of a view in IB, you do not need to do it again programmatically, although you may. myScrollView.backgroundColor = [UIColor clearColor]; will make your UIScrollView transparent.
Like said in the title, I have a problem with an UITableView which is in my app a subview of an UIScrollView. In my UIScrollview I have several images, labels, etc. and at the bottom my UITableView is set. I can fill the table view with values etc., but when I try to select a cell by touch, nothing happens.
To see the UITableView, you must scroll down a little bit in the UIScrollView. Maybe this is the issue? How do I solve this problem?
Thanks!
When I have to do this kind of thing I use to put all the content that is on the top of the UITableView in a UIView and set this view to the tableHeaderView of the tableView. For example:
UIView * vwHeader = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
// set the content of the header
// ...
_tblView.tableHeaderView = vwHeader;
This way, this header will be part of the table scrolling and you won't need a scrollView. You can do the same with the tableFooterView.
UITableview is
Inherits from
UIScrollView : UIView : UIResponder : NSObject
So why do you put your tableview inside the hscrollview? Don't do this.
Then unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.
I have a UITableView in iPhone with enough cell to make it scrollable.
I would like to have a subview display whenever I click on a cell, rather than using the navigation controller behaviour.
The problem is that I cannot calculate the CGRect exactly to have the subview always centered in page, because the CGRect is calculated from top of table, and if I scroll table and click cell, the subview will be added out of screen.
The solution could be easy, but I don't know if it's possible: identify the portion of the current viewable area of the UITableView and obtain in some way the frame and therefore origin and size, then build a subview based on such coordinates.
Do you think it's possible without writing not too much code ?
thanks
Leonardo
A simple solution is to not add your sub view as a subview of the UITableView but of its parent (or the main application window). So instead of doing something like:
[myTableView addSubview:mySubView];
do:
[[myTableView superview] addSubview:mySubView];
I have a UITableViewController inside of a UINavigationController.
I want to have a UIView appear over the top of the table view but not susceptible to the scrolling of the table view.
I.e. if the table view is scrolled, the UIView should remain in the same position relative to the screen, rather than relative to the table view. It should appear anchored in a certain position.
What is the best way to achieve this?
EDIT: To clarify, the view should float transparently over the top of the table view.
Many thanks!
I also wanted to have a floating UIView over my tableView.
So, within my RootViewController (which is a UITableViewController), this worked for me
- (void)viewDidLoad {
/* mylabel is a UILabel set in this class */
[self.mylabel setUserInteractionEnabled:NO];
/* navigationController comes from higher up in the navigation chain */
[self.navigationController.view addSubview:self.mylabel];
}
Similar to what Peter said, create a UIView that will contain both the TableView and the subclassed UIView. Such as:
UIView *view = [[UIView alloc] initWithFrame:frame]; // Define frame as you like
[view addSubview:myTableView]; // This is the reference to your tableView
[view addSubview:myAnchoredView]; // This is the reference to your UIView "floating" subclass
You will also need to turn off user interaction for your floating view. I don't know if this will specifically pass the touches to the underlying UIView's or not though:
[myAnchoredView setUserInteractionEnabled:NO];
If this is blocking touches to your tableView, you may need to pass the reference to your tableView to the anchored view at initialization, then pass the touch events along. You can do this by overriding the touch response methods in UIResponder. (If there is a better way, someone please speak up.)
Do you mean the anchored view should appear transparent over the UITableView, or just above, i.e. anchored view uses top 20% of the available space, table view uses the rest?
In any case, create a UIView containing the anchored view and the table view. If you want the anchored view transparent over the table view, it's a bit tricky, because to scroll the table view, touches have to pass through the anchored view.
Add the surrounding view's view controller to the navigation controller instead of just the tableview.
I investigated how UIScrollView keeps its scrollIndicator above the UIScrollView's content and yet unmoving by examining a UIScrollView in the debugger.
The scrollIndicators are UIImageViews. And you can see they are direct descendants of the UIScrollView itself. You can also see that any scrolled content is also a direct descendent. So how is it that the scroll indicators don't move?
I tried updating the position of my static content constantly in - (void)scrollViewDidScroll:(UIScrollView *)scrollView this, surprisingly, works. I'm not sure if it is how UIScrollView itself does it, but without some private magic, it must be something like this.