iOS 7 status bar overlap the text in view - iphone

iOS 7 status bar overlap the view. The text shows in the header of the screen. I want to show the screen with out the text in header called "Carrier, 4:49, and Battery"
How to handle this in iOS 6 and iOS 7 ?

You could hide it, I think that would look better in your case.
In your app plist add this
View controller-based status bar appearance, and set to NO

I think that it can help you:
if ([self respondsToSelector:#selector(edgesForExtendedLayout)]) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}

Its not a iOS 7 problem. Because status bar is transparent in iOS7. So you need to handle it manually.So please use right image here.

Unfortunately you are not the only one with this problem,
while on iOS before 7 the {0, 0} point was just below the status bar it is now at the top of the screen my advice is to add +20.0f to every y coordinate if in iOS 7
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
// normal comportment
} else {
// add 20.0f offset
// you might also want to add a UIImageView subview to go behind the status bar (20pt of height, full width)
}
you might do it in view didLoad, for my part I calculate my elements position in static variables initialized in the +(void)initialize class method of my view controllers
if in -(void)viewDidLoad something like
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
// normal comportment
} else {
for (UIView *v in self.view.subviews) {
CGRect oldFrame = v.frame;
v.frame = CGRectMake(oldFrame.origin.x, oldFrame.origin.y + 20.0f, oldFrame.size.width, oldFrame.size.height);
}
// you might also want to add a UIImageView subview to go behind the status bar (20pt of height, full width)
}

This may help you How to fix iOS 7 Status bar overlapping issue and status bar style
which worked for me.

Related

NavigationBar hides TableView in TabBarViewController

I have a ViewController that Pushes a TabBarViewController. Inside that TabBar View Controller I have 4 tabs. Two of these tab bars are UITableViewControllers and the other two are ViewControllers. The first tab is a table view controller and is working fine, ie not being hidden by the navigation bar. The third tab, which is another TableViewController, is being partially covered by the navigation bar. The first section and first cell is being hidden underneath the navigation bar. Has anyone had this problem in the past or does anyone know a solution to this? I've tried a couple of things like resizing the frame size manually
self.tableView.frame = CGRectMake(10,10,self.view.bounds.size.width -20, self.view.bounds.size.height-20);
That did't seem to work. I tried AutoLayout as well and didn't work. I don't know what else to do. Anyone have any suggestions or ideas of how to tackle this.
Edit: I've tried the edgesForExtendedLayout but it is making my navigationbar a darker color. It animates the color change in the navigationbar, sort of like a loading bar.
Note: This is only happening in ios7. I just simulated it in iOS 6.1 and the navigationbar does not cover the table view controller at all, which is weird to me. Any one have any suggestions?
Edit #2: Noticing that this is an iOS 7 > problem i did the following but now the navigation bar has changed color to a darker color.
if([[[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:#"."][0] intValue] >= 7)
{
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
{
self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = YES;
self.automaticallyAdjustsScrollViewInsets = NO;
}
}
In the viewDidLoad method of UITableViewController (assuming it's loaded with a call to the tabBarController) that is associated with the tabs use
if ([self respondsToSelector:#selector(edgesForExtendedLayout)]) {
self.edgesForExtendedLayout = UIRectEdgeNone;
self.tableView.contentInset = UIEdgeInsetsMake(0., 0., CGRectGetHeight(self.tabBarController.tabBar.frame), 0);
}
I fixed that with:
if ([self respondsToSelector:#selector(edgesForExtendedLayout)]) {
viewcontroller.edgesForExtendedLayout = UIRectEdgeNone;
viewcontroller.extendedLayoutIncludesOpaqueBars = NO;
viewcontroller.automaticallyAdjustsScrollViewInsets = NO;
}

contentSizeForViewInPopover different height in IOS4 and IOS5

Hello,
I have UITableView with static content embedded in UIScrollView
so I have just set size in popover:
- (CGSize)contentSizeForViewInPopover
{
return CGSizeMake(600, 670);
}
but, I got different popover heights (see attachments). In IOS4.3 height is bigger than in IOS5.
I don't want to check IOS version and increase/decrease height.
Please advice.
Thanks
As far as I know, when using the navigation controller as popover contents, you have to
set the contentSizeForViewInPopover on the root controller (or anyone that is being shown as the first). (Don't try to set size on the navigation controller).
whenever you push/pop controllers and you want the popover size changed for the new controller on the stack, call setPopoverContentSize:animated: explicitly. A UINavigationControllerDelegate is good for this.
You can dynamically calculate the height of your popover based on the height of your tableview and overriding contentSizeForViewInPopoverView like this:
- (CGSize)contentSizeForViewInPopoverView {
CGFloat width = 200.0; // Currently no way to obtain the width dynamically, only height.
CGRect rect = [self.tableView rectForSection:[self.tableView numberOfSections] - 1];
CGFloat height = CGRectGetMaxY(rect);
return (CGSize){width, height};
}
This assumes you have 1 section. If you have more, you just need to use rectForSection to determine the height of each section and add them up.

UIView positioning in IB of Xcode 4

Consider the screen shot above. The UIView is positioned too much to the top causing the upper test string to be partially off and there is a gap shown at the bottom screen. The screen shot also shows its corresponding positioning values in IB : x = 0 and y = 20. So there is actually an offset (y = 20) default to clear the top status bar. But still the status bar shown covers part of the UIView.
The x, y entry is greyed out, so it seems not possible to change its values. Have spent quite some time but still not able to solve this seemingly easy problem. Hope that somebody who is familiar with this could give some hints on how this should be done.
Update :
Have done it in code as suggested. It seems to work ok. If you find any errors please let me know ...
- (void)viewDidLoad
{
CGRect position_and_size;
CGPoint cg_point;
CGSize cg_size;
[super viewDidLoad];
// setup after loading the view from its nib.
NSLog(#" --- Screen loaded --- ");
cg_size.width = 320;
cg_size.height = 460;
cg_point.x = 0;
cg_point.y = 20;
position_and_size.origin = cg_point;
position_and_size.size = cg_size;
[[self view] setFrame : position_and_size];
}
.
The following is the latest screen shot :
The problem is that you're placing a view that's 460 pixels high at {0,0} in a window that's 480 pixels high. The first 20 pixels of your view therefore ends up under the status bar, and the view fails to cover the bottom 20 pixels of the window. You can fix it in any of the following ways:
Change the autoresize options so that the view's size will be automatically adjusted to fill the window.
Resize the view to match the window's bound, either in code or in IB.
Position the view at {0,20}, either in code or in IB.
You can fix it programmatically:
[yourSubView setFrame:self.view.bounds];
Assuming self.view - parent view, where it should fit.

How do I get the width of a UITabBarItem?

The width of a UITabBarItem varies, depending on how many there are.
How do I determine how wide my tab bar items are?
I'm looking for a property if possible, as opposed to a mathematical formula, since on the iPad, there is also an issue of padding on either side of the tab bar. Consider these screenshots. Notice the padding on either side of the tab bar items on the iPad (highlighted with the red boxes). This padding does not exist on the iPhone.
The iPad:
The iPhone:
Edit: It has been noted in the comments below that this solution did not work in a beta version of iOS 5, so be prepared to modify it to meet your needs.
I think in order to do this the right way, you have to be able to get to the frame of each tab bar item. Fortunately, this is possible:
CGFloat tabBarTop = [[[self tabBarController] tabBar] frame].origin.y;
NSInteger index = [[self tabBarController] selectedIndex];
CGFloat tabMiddle = CGRectGetMidX([[[[[self tabBarController] tabBar] subviews] objectAtIndex:index] frame]);
The above code gives you the y coordinate of the top of the tab bar and the x coordinate of the middle of the selected tab item. From here, you can add your indicator view to the tab bar controller's view relative to this point.
Disclaimer: The danger with this approach is that it peeks under the hood of the UITabBar class by accessing its view hierarchy and the frame property of instances of the private UITabBarButton class. It is possible (however unlikely) that this approach could be affected/broken by a future iOS update. However, you're not accessing any private APIs, so this shouldn't get your app rejected from the App Store.
I made a simple iPad project demonstrating how it works, complete with animations.
Swift 3
I created a shared instance in UIApplication then pulled my subviews width
tabBarController?.tabBar.subviews[1].frame.width
UITabBarItem inherits from UIBarItem, which inherits from NSObject. Since it doesn't inherit from UIView, I don't know that you're going to be able to get the information you want just with a property. I know you don't want a mathematical way of doing it, but it would seem that getting the frame of the tab bar and dividing by the # of tabs would be a reasonable option that should work regardless of the hardware (iphone vs ipad). Padding shouldn't affect this, right? So you'd have:
tabSize = tabbar.frame.size.width / [tabbar.items count];
tabBarStart = tabbar.frame.origin.x;
// Assume index of tabs starts at 0, then the tab in your pic would be tab 4
// targetX would be the center point of the target tab.
targetX = tabBarStart + (tabSize * targetTabIndex) + (tabSize / 2);
I, as well, am interested to know if someone finds a simple property to give this information.
Looking at the answer above:
Items in the UITabBar work different in the iPhone and the iPad. In the iPhone they fill whole width, in the iPad they're centered horizontally.
There is a spacing between the items in the iPad.
You can set the values for both width and spacing using tabBar.itemWidth or tabBar.itemSpacing. You are not able to read system spacing or width from it - you'll receive 0 unless you set it.
So here's my sample how to get frames of all UITabBarItems:
// get all UITabBarButton views
NSMutableArray *tabViews = [NSMutableArray new];
for (UIView *view in self.tabBar.subviews) {
if ([view isKindOfClass:[UIControl class]]) {
[tabViews addObject:[NSValue valueWithCGRect:view.frame]];
}
}
// sort them from left to right
NSArray *sortedArray = [tabViews sortedArrayUsingComparator:^NSComparisonResult(NSValue *firstValue, NSValue *secondValue) {
CGRect firstRect = [firstValue CGRectValue];
CGRect secondRect = [secondValue CGRectValue];
return CGRectGetMinX(firstRect) > CGRectGetMinX(secondRect);
}];
Now you have a table of frames, corresponding to your tabbar items. You can eg. place an imageView on selected index button frame.
CGRect frame = self.tabBar.bounds;
CGSize imageSize = CGSizeMake(CGRectGetWidth(frame) / self.tabBar.items.count, self.imageView.image.size.height);
CGRect selectedRect = sortedArray.count > self.selectedIndex ? [sortedArray[self.selectedIndex] CGRectValue] : CGRectZero;
[self.imageView setFrame:CGRectIntegral(CGRectMake(CGRectGetMinX(selectedRect), CGRectGetMaxY(frame) - imageSize.height,
CGRectGetWidth(selectedRect), imageSize.height))];
I tried these 2 properties of UITabBar:
#property(nonatomic) CGFloat itemWidth NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR;
#property(nonatomic) CGFloat itemSpacing NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR;
But get zero value as Vive said. So I wrote some codes to get the right width:
CGFloat tabBarItemWidth = 0;
for (UIView *view in [self.tabBarController.tabBar subviews]) {
if ([view isKindOfClass:NSClassFromString(#"UITabBarButton")]) {
if (tabBarItemWidth == 0) {
tabBarItemWidth = view.frame.origin.x;
} else {
tabBarItemWidth = view.frame.origin.x - tabBarItemWidth;
break;
}
}
}
Why not use the width of first UITabBarButton? Because there are spaces between tab bar buttons. :)
You can get tabBarItem view using private property view. Then just get view frame.
- (CGRect)rectForTabBarItem:(UITabBarItem *)tabBarItem {
UIView *itemView = [tabBarItem valueForKey:#"view"];
return itemView.frame;
}
Loop through your tabBar's subviews and find the views with the class "UITabBarButton". These are the views for each tab item.
for (UIView *view in self.tabBar.subviews) {
if ([view isKindOfClass:NSClassFromString(#"UITabBarButton")]) {
// view.frame contains the frame for each item's view
// view.center contains the center of each item's view
}
}

UIWebView under transparent UINavigationBar

I have a UIWebView which I want to put under my translucent UINavigationBar. Normally when I put a UIScrollView under a translucent UINavigationBar, I set its contentOffset such that all content will be initially pushed after the bar so that it can be seen; thereafter, the user can scroll text and it will underlap the bar.
The problem is that UIWebView appears not to be a proper subclass of UIScrollView; thus, I can't use setContentOffset. Does anyone have any tips or tricks on getting a UIWebView to look good with a translucent navigation bar? Thanks.
As of iOS 5 you can use the scrollView property of UIWebView, and set a contentInset to adjust the positon.
CGFloat top = 0.0;
if( self.navigationController != nil && self.navigationController.navigationBar.translucent ) {
top = self.navigationController.navigationBar.bounds.size.height;
}
UIWebView* wv = ...
wv.scrollView.contentInset = UIEdgeInsetsMake(top, 0.0, 0.0, 0.0);
The easiest way is to set:
webView.clipsToBounds = NO;
webView.scrollView.clipsToBounds = NO;
It work on bouth iOS 7 & 6, and I didn't try, but on iOS 5 probably too
I achieved this by setting the UIWebView subviews to not clip to bounds, then I could put a toolbar on top of it and get the desired effect:
for (UIView *subview in theWebView.subviews) {
subview.clipsToBounds = NO;
}
I am not sure if there is a clean method to doing this. I have not tried it, but here is an idea:
draw the uiwebview at origin 0,0
intercept all screen touches
if you detect the user dragging up (scrolling up the webview), dont pass the touch on
Instead, move the webview up x pixels so its origin is (0,-x). Then change the height to add x pixels
Youy will need to keep some sort of state so that you know when to stop resizing the webview and start passing on the touches so the webview will scroll.
Getting it back is the same only you do it on a drag down (scrolling down the webview).
Another way to possibly do this is to insert a div in the html code you are rendering so that it is spaced out up on the top of the page. make sure you set your zoom correctly and set the uiwebviews origin to (0, -x) to begin with.
With the advent of iOS 7, the offset height would now need to include the height of the top status area. Otherwise, iOS7 devices will have 20 pixels of webview still hidden under the navigation bar.
In a project that needs to support iOS 7 and older devices, a macro like the one found
here:
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
Can be very useful.
A modified version of zerotool's helpful code listed above could now look something like this:
if (self.navigationController != nil && self.navigationController.navigationBar.translucent) {
top = self.navigationController.navigationBar.bounds.size.height;
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"7.0")) {
top += [[UIScreen mainScreen] applicationFrame].origin.y;
}
}
// (etc.)