UITabBar appears 20 pixels down? - objective-c

I have created a UITabBarController and adding to a UIViewController subview.
My code is implemented programmatically.
The UITabBar is showed up 20pixels down the view.
UITabBarController *tabCtrl_obj = [[UITabBarController alloc]init];
[self.view addSubview:tabCtrl_obj.view];
How should i solve it?

It's the status bar that's doing it. Sometimes if you add a view directly to the window it can behave oddly - generally it means you have to define more elements of the view yourself. Try reducing the size of your view by 20 pixels (probably to 460) and then removing the simulated status bar in interface builder. How much are you doing programmatically?

Related

Always visible UIView

I want to place a UIView that will inform the user what is the status of the app. I want that view to be visible even if the user switches views, same thing as the UINavigationBar is always visible, but I don't want to use that bar, I would like to add another view that will show a message.
How can this be done? I can't add the view to the current view, because it will disappear, if the user changes views.
It should be added to the window? But how? I would then have to resize the views so that my new view can fit, but how?
Thanks.
Create a container view controller and set it as the rootViewController of the apps window.
Inside this container you have your status view, and you also resize the windows real rootViewController to take up the remaining space as a subview. If you are using a standard container view conrtoller (tab, navigation etc) as the root then you can use standard navigation methods and the status view will always be visible
There would be problems if you wanted to present modal views though, since these would go over the top of the status view
In your appDelegate.m add your view as subView of window.
UIView *mainBg = [[UIView alloc] init];
mainBg.frame = newframe;
[self.window addSubview:mainBg];
If you have a UINavigationController you can add your view to its view.
[self.navigationController.view addSubView:yourView];
Presenting modal views would cover the view, as stated in the other answer.

How to make current view a scrollview? iOS / Objective C

I have a view (that is actually part of a UINavigationControllers view) that i want to make a scrollview.
how do i do that?
could i do something like this:
UIScrollView * content = [[UIScrollView alloc] initWithFrame:self.view.bounds];
self.view = content
(obviously that doesn't work, but is there a way to do it like that)?
Yes, it is, you have to implement delegates, and set the contentSize. The best tutorial on scrollViews ever I found is:
http://www.raywenderlich.com/10518/how-to-use-uiscrollview-to-scroll-and-zoom-content
You are on a good way!
You can create the scroll view programmatically like you do and then add the existing view as a subview of this new scroll view, examine addSubview: (which works on all UIViews and subclasses like UIScrollView as well). I won't say this is the solution or even a clean one for that matter, but if you read about addSubview: you can at least figure out how to have a view live inside a scroll view...

Change layer of images

Is there a way to change the "layer" that UIImageView objects are drawn in? Whenever I add an image view to a view controller it defaults to drawing the most recently added one on top of all the others. So if I decide to add a "background" image it is now a "foreground" image and blocks everything else.
There isn't anything in the IB options or in the UIImageView class reference and I haven't been able to find anything here on SO. It's been a problem for a while and it's weird that I haven't seen anything about it before... I think it might just be my semantics coming from a delphi background.
Anyway, does anyone know about this issue / ICANHAZTEHCODEZ to fix it? Or is this just like the UIScrollView problem and poorly supported by the development environment.
This happens when I try to use the editor to arrange the subviews.
You can bring a SubView to Front or Send it background programmatically using
[self.view bringSubviewToFront:yourImageView];
and
[self.view sendSubviewToBack:yourImageView];
when self.view must be the superview of your imageView
In IB, select a UIControl and from top menu bar select Editor->arrage->send to front or back
When you use UIView's addSubview: method, it will add it to the top of the view stack resulting in what you are seeing.
There are numerous other UIView methods you can use to determine the order of subviews. E.g.:
- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;
- (void)sendSubviewToBack:(UIView *)view;
- (void)bringSubviewToFront:(UIView *)view;

UITableView first row is cut off

What would cause the first row of a table in a nav controller to be positioned so part of it is under the nav controller?
I cannot seem to get it to show the whole row top to bottom; It may seem minor, but it's clearly not correct and I find it unattractive.
TableViewController added to nav controller entirely in code:
SettingsRootController*settings=[[SettingsRootController alloc] initWithStyle:UITableViewStylePlain];
self.settingsView=[[[UINavigationController alloc] initWithRootViewController:settings]autorelease];
[settings release];
SettingsRootController is a subclass of UITableViewController.
It seems that it is a common problem with programmatically-added UINavigationController - see Adding a UINavigationController as a subview of UIView.
Basically, what you should probably do is to set the frame property of UINavigationController before you add it as a subview to anywhere. In the accepted answer to the above question there's also a suggestion to alter the UINavigationController's frame to:
nav.view.frame = CGRectMake(nav.view.frame.origin.x, nav.view.frame.origin.y - 20,
nav.view.frame.size.width, nav.view.frame.size.height);
the only thing that seems to work is manually shifting the table view inside the nav controller down by 10 pixels, but only on iPhone, not on iPad, since there is no alignment problem on iPad and shifting by 10 pixels on iPad creates a gap. this is clearly some sort of nav controller bug, as there are other weird issues noted in other threads.
CGPoint tableorigin=CGPointMake(0,ISIPAD?0:10);

iPhone view controller view shifted down 20 pixels when rotating to landscape

I am trying to implement a custom tabbarcontroller using a UIViewController and a UITabBar. Everything is working fine so far, except when I rotate the device to landscape, the UIViewController shifts the entire view down 20pixels, creating a black bar between the status bar and the view. Even when the view is rotated back to portrait orientation, the view is still shifted down 20pixels.
What do I need to do to remove the black bar? Do I have to perform custom rotations? If so, where should I insert these rotations?
Before rotation:
After rotation:
I've experienced this same issue.
This discussion was helpful: UIWebView on iPad size
Tony's answer helped me discover that when you create a subview it's helpful to setup code similar to this:
UIWebView *webView = [[UIWebView alloc] init];
webView.frame = self.view.bounds;
If you post some of your code I may be able to provide more specific advice.
Rather than shifting all views down, try DELTA properties in Interface builder.