Programmatically center icons in a TabBarItem in a UITabBarController - iphone

I'm programmatically generating a UITabBarController (instantiating view controllers and assigning them to my UITabBarController's viewControllers array). I don't want titles for my TabBarItems. However, the TabBarItems by default make space for a title, so my icon images are centered 5 pixels higher than they should be. Is there a programmatic way to "center" i.e. shift or give offsets to the TabBarItem's image?

You can use the imageInsets property to move the frame of the icon.

Unfortunately, there isn't a way to do this (and even if you managed to cheat and find a way to shift this stuff down it would no doubt be denied by Apple during the approval process).

Related

How to add an image view sharing between navigation bar and view?

I had to add an image so that half of it is in the navigation bar and remaining is in the view.I know there is always a probability of adding two images,but i want to know is there any way to add an image view(only one)between the two?Now i know i can do this way ,
[self.navigationController.navigationBar addSubview:imageView];
and also self.view addSubview:imageView,but i need a single image view to be shared between the two
ie the first half is in navigation bar and the remaning is in the view.can anybody help me on this?
No, this is not possible AFAIK. A view (including a UIImageView) can only have one superview. SO it's either a child of the UINavigationBar or one of the other view, but not both.
with ios 7 you can use translucent navigations bars so that you can set the imageview in your view and it shines through the navbar :-)

White space after moving uitabbar to the top

I use UINavigationcontroller inside UITabBarController and I have moved the UITabBar to the top .The UITabBar has moved successfully but the problem is, there is about 50px of white space where the tab bar used to be .
Anyone has a solution to this problem????
loop through the subviews of the tabbarcontroller.view until you find the container for the tabbar's inner views, then set the frame of that view to 50px higher than it currently is.
Alternatively, a better solution is not to try and use a tabbarcontroller this way. Just use a standalone UITabBar and implement your own view swapping logic when the tabs are tapped.
Uncheck extended edges in rectangle.

UIPopoverController in application window

I am creating a UIPopoverController from the application delegate and I want to center it on the window, how ca I do that?
You can specify the rectangle that it is anchored to when you display it. Just specify an rectangle and direction that guarantees it will be displayed in the position you want.
It does sound like you may be doing something that would be best done by presenting a custom UIView as a new subview instead of using a popover. The popover will always have the little arrow coming off the side.

Why do my UIImageviews get resized/dimmed when using UINavigation/UITabbar controller

I have an app with a primary view that has a UITabBarController with 5 tabs. Each tab is a UINavigationController.
In interface builder, I'm customizing the background of each page by dragging a UIImageView and setting it fullscreen. The image I'm setting to the view is 640x960. I am setting it to be Aspect Fill.
However, what I've noticed is that it is not where I would expect it to be. When navigating between by tabs, the image seems to be shifted down from where it should be.
Also, when pushing a new view to the navigation controller, the background of this new view isn't offset in the same way as the tabbar one, and it is also slightly dimmed.
How can I set my UIImageViews on each page to be aspect correct and fill the screen 1:1? Also, how does one disable the dimming when pushing a view to the navigation controller?
Thanks for any tips, and apologies if this is covered in another thread, I couldn't find an answer searching the site.
Assuming that you are using the IB to setup your views, you should select navbar/tabbar options to reflect what will be on the actual page. That should place your image correctly. I would also recommend that you make both a low res and hi res version of your background images -- 320x480 and 640x960. Of course, your size may need to be adjusted (reduced) for the navbar and/or tabbar which will leave less than 960 px of vertical height -- probably more like 920px if you are in portrait mode. Then you add #2x to the base name of the hi res version, this would account for older iPhone screens.
Once you have the image placed correctly, resizing should be unnecessary. You can have the image automatically resize width and height using the little arrows on the layout page -- that's a bit hard to describe. It can also be done in code -- if you still need that I can provide a sample.
Maybe you need to set all AutoresizingMask in order to resize the UIImageView properly on each view. And to main aspect ratio u should use either AspectFill or AspectFit on the contentMode.

Centering the contentView within UIPopoverController

In my UIViewController that I use for my UIPopoverController, I have a label on top, a segmented control, and then a UITableView below it. When I created my .xib for the content view, I put in a table, and centered the label and segmented control within the .xib.
When I present the popover, I do not want it taking the whole screen. I use about (800,700) points to display the popover, but then the labels do not look right. They are not centered within the popover since the popover is now smaller than the .xib. What I did was move the label and segmented control to the left to make it centered in IB. That doesn't seem the best and future proof way of doing it. I was hoping I could do something programatically by taking the width size and dividing by 2 or something and centering based on that. Any advice? Thanks.
There are a couple of options:
Check out the documentation for the popoverContentSize property on the UIPopoverController, you should set it to be the size of the XIB that provides the content (so the XIB and popover both have the same size/contentSize, essentially).
Set the autoresizing masks on the subviews in the XIB so that they lay themselves out correctly dependant on the size of the XIB. To center them within their parent view you do NOT want the left and right mask setting (they should both be deselected in Interface Builder). This guide covers centering subviews: http://www.techotopia.com/index.php/IPhone_Rotation,_View_Resizing_and_Layout_Handling