iPhone X Safe Layout Area in Objective-C App - ios

I am working on an app writted in Objectice-c without storyboard & Autolayout.
I am facing issue in iPhone X (Please see below)
---iPhone X---
---iPhone SE---
Below is the code for Bold title what I have written
_topHeaderLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 20, CGRectGetWidth(self.view.frame)-60, CGRectGetHeight(self.view.frame)* 0.2)];
_topHeaderLabel.text = #"Please select bank account you want to link";
_topHeaderLabel.textAlignment = NSTextAlignmentCenter;
I can see UI is perfect in all iPhone devices except iPhone X. Please let me know what am I doing wrong here. I can't apply auto layout as the app is already written.
Any Idea or suggestion would be great.

there is a problem in your height it must be
_topHeaderLabel.sizeToFit()
plus check this if detect device is X -> self.view.safeAreaInsets.top
Try this in IPhoneX , top inset in IPhoneX is 44 but you're setting 20 , if you use navigatioBar it'll be 88
UILabel*topHeaderLabel = [[UILabel alloc] initWithFrame:CGRectMake(30,self.view.safeAreaInsets.top, CGRectGetWidth(self.view.frame)-60, CGRectGetHeight(self.view.frame)* 0.2)];

Related

Screen hight with (UIScreen) is fine in iPad but wrong in iPhone

I am developing a game where a background is moving at the back. I sat the background hight using the below code. It is working fine with iPads but with iPhones it is not taking the proper hight of the screen; instead it is in the middle of the screen with almost half the hight of the screen! The application is only working in portrait orientation. This is for xCode 8 & SWIFT 3
Please check below the code I am using for the background
hight:
let screenSize: CGRect = UIScreen.main.fixedCoordinateSpace.bounds
background1.size.height = screenSize.height
Thanks in advance
I have resolved the issue but using a (workaround) rather than resolving the root cause as I could not identify it.
First I have noticed that when sizing the hight of the screen I have 2 conditions:
below code will work with all iPhones but not iPads:
background1.size.height = self.frame.height
below code will work with all iPads but not iPhones:
background1.size.height = screenSize.height
So since the minimum hight of screen of iPads is 1024; I used the below code to first check if it is iPad use condition 2 and if iPhone use condition 1 as follow:
let screenSize: CGRect = UIScreen.main.bounds
if screenSize.height < CGFloat(1024) {
background1.size.height = self.frame.height ////for iphone
} else {
background1.size.height = screenSize.height ////for ipad
}
I am not sure what your case is.But it happens in iPhone 5+ devices due to launch screen size.Normally it behaves like iPhone 5 screen size even with iPhone 6,iPhone 6+.
Now the soultion.
1.You can use the default launch screen storyboard to avoid the problem.
2.You have to add every sizes for iPhone screen size (320*480,640*960,640*1136,768*1334,1242*2208).please add also iPhone 7,7+ sizes too.
3.You can use asset Catalogs for launch screen.
If thats the case for you please use above solution.It should work.

Custom navbar sizing from iphone 5 to iphone 6

I have a custom tab bar that was optimized for the iphone 5.
UINavigationBar *myBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
[self.view addSubview:myBar];
When it on the iphone 6, part of it is cut off of course because it only goes to 320 pixels.
How do i fix this? Is there a way to check which iphone its being ran on, and then run the pixel specified code? I plan on putting a background image on this navbar later so it must be centered.
In general it is a bad idea to hard code dimensions like this. This will break if you rotate, or if viewed on a screen with a different size than the original iPhone screen.
Many of these controls have a default size that you can use to your advantage. Instead of handing it a frame, consider just modifying the frame it gives you:
UINavigationBar *myBar = [[UINavigationBar alloc] init];
CGRect navBarFrame = myBar.frame;
navBarFrame.size.height // returns the right size for the current OS
navBarFrame.size.width = self.view.frame.size.width;
myBar.frame = navBarFrame;
This type of defensive coding is helpful in keeping your app laid out properly under many conditions, including when you embed this control into a parent view controller, or viewed on tomorrows larger-screened iOS devices.
All this said, are you sure you don't want a UIToolbar? Typically you don't ever create your own UINavigationBar, as that class is just used in UINavigationController for you.
UINavigationBar *myBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 50)];
[self.view addSubview:myBar];
may be this help you.

Different positioning on iOS7 iPad Mini and iOS6 iPad 3

I have a simple placement of a UILabel in my app's code:
headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5, 884, 68)];
headerLabel.font = [UIFont fontWithName:#"HoboStd" size:64];
headerLabel.textAlignment = UITextAlignmentCenter;
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.textColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:1.0f];
headerLabel.adjustsFontSizeToFitWidth = YES;
[self.view addSubview:gameSpeaks];
On an iOS6 iPad 3 the text is showing a little higher up on the screen than it is on the iOS 7 iPad Mini with the same code, same .xib and everything. Does anybody know if this is a result of iOS6 vs iOS7 or if it is a result of the different devices or some other issue I am not aware of?
I WANT to say that the iPad Mini was showing the text in the same position as the iPad 3 when I was testing with it on iOS6, and then I upgraded it to iOS7 and noticed this difference. If it is the OS version that is causing this issue - what is the preferred way for testing for OS version in code so that I can reposition the label as needed when running on an OS7 device vs OS6?
Thanks so much!
It's a result of iOS6 vs iOS7 given that the status bar is now part of the view.
In iOS7, everything will appear about 20 pixels farther up than it did in iOS6 and previous if you do not adjust them.
In iOS6 and previous, setting a UI element's y origin to 0 would put it at the very bottom edge of the status bar. In iOS7, a y origin of 0 will now put it at the very top edge of the screen, behind the (now transparent) status bar.
You can get the current version of a device using:
[[UIDevice currentDevice] systemVersion]

How to adjust UITableview margins from left and right programmatically?

i have a tableview(no table view cell). My Application is running fine in iOS 6 but when i am running it in iOS7 Tableview margin is conflicting.When i am setting up frame via Code its margin is only adjusting from left and bottom. i am using following code
if([[[UIDevice currentDevice]systemVersion]floatValue]>=7){
CGRect newSize = CGRectMake(0,0,730,925);
newSize.origin.y = 0;
newSize.size.width = 728.0;
newSize.size.height = 925.0;
self.myTable.frame = newSize;
}
Please suggest me something how can i resolve it
?
Here are images for ios 6 & ios 7 (Its a group table view ) i havent changed any margin for ios 7 its same as in ios6 ,and if i am doing any changes in ios 7 regarding margin its affecting in ios 6 layout too..
Add autoresize property
//ensure autosizing enabled
self.view.autoresizesSubviews = YES;
myTable = [[myTable alloc]initWithFrame:self.view.bounds];
[myTable setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[self.view addSubview:myTable];

Bar translucency gone in iOS 7.0.3

Compare the two screenshots:
Done on iOS 7.0 simulator
And the one done on iOS 7.0.3 iPhone 4S:
Same code here and there and same stuff! Any idea why the translucency is gone on the real device?
I have this code to simulate it (I know it's probably awkward and not right but that's how it is):
topMenuView = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, 0, self.view.frame.size.width, TOP_BAR_ORIG_HEIGHT)];
topMenuView.clipsToBounds = YES;
UIToolbar *topMenuViewBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, -4, self.view.frame.size.width, TOP_BAR_ORIG_HEIGHT + 4)];
topMenuViewBar.barStyle = UIBarStyleDefault;
topMenuViewBar.barTintColor = [BSFunctions getColorFromHex:#"1ea6ff"];
const CGFloat statusBarHeight = 20;
UIView *underlayView = [[UIView alloc] initWithFrame:CGRectMake(0, -statusBarHeight, topMenuViewBar.frame.size.width, topMenuViewBar.frame.size.height + statusBarHeight)];
[underlayView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
[underlayView setBackgroundColor:[BSFunctions getColorFromHex:#"1ea6ff"]];
[underlayView setAlpha:0.36f];
[topMenuViewBar insertSubview:underlayView atIndex:1];
UIView *underlayView2 = [[UIView alloc] initWithFrame:CGRectMake(0, -statusBarHeight, topMenuViewBar.frame.size.width, topMenuViewBar.frame.size.height + statusBarHeight)];
[underlayView2 setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
[underlayView2 setBackgroundColor:[BSFunctions getColorFromHex:#"0291ff"]];
[underlayView2 setAlpha:0.36f];
[topMenuViewBar insertSubview:underlayView2 atIndex:2];
[topMenuView addSubview:topMenuViewBar];
[self.view addSubview:topMenuView];
The main point is it used to work before on the device! But after iOS 7.0.3 came out it changed. I'm noticing the same behavior in Facebook and Fitocracy iOS apps.
UPDATE
On Xcode 5.0.1 with iOS 7.0.3 simulator we have this (which is different from the first image on iOS 7.0 simulator as you can see):
OK, so after having played around with the colours a bit more, I managed to get a similar sort of appearance with the blur!
Previously, I was setting a barTintColor on the navigation bar appearance which had the following values:
R:17
G:63
B:95
A:1
This was fine in iOS < 7.0.3, and the output color in the nav bar (with the blur effect) was actually:
R:62
G:89
B:109
Since iOS 7.0.3, the barTintColor seems to take into account the alpha value of the color we set. This meant that the nav bar was actually outputting a solid color 17,63,95, and there was no blur effect.
The key to getting the blur effect back is setting an alpha < 1 in the barTintColor.
After lots of guess work and trying different RGB values, I managed to get the exact same RGB output from the nav (and tab) bar, using the following RGBA:
R:4.5
G:61.6
B:98
A:0.65
It does not look like there's a magic ratio to apply to the previous color to obtain the new one.
Anyway I've actually rejected the binary that got approved this afternoon, and have re-submitted with these new values so that user's don't get an ugly app :)
Hope this helps.

Resources