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]
Related
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)];
I have a PNG image that I am re-colouring at runtime:
logo.image = [[UIImage imageNamed:#"logo.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
logo.tintColor = [UIColor whiteColor];
This appears white on my iPhone 6, all the simulators etc; but it is a slightly darker grey colour on an iPhone 6+. Could there be a reason I've missed?
Here's a screenshot of the iPhone 6+ (all the navigation items should be white - like every other device)
barTintColor is made translucent by default unless you set the
translucent property to NO.
Try this
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.navigationController.navigationBar.translucent = NO;
as we know in iOS 7 the status bar overlaps with a view but not in iOS 6 .
I developed whole application for iOS7 and now I being asked to make iOS6 support for it
but it is just a mess.
as we see in this Overlaps the status bar on view iOS7 question there is solution for iOS 7 to be like iOS6
but can I make it opposite way ? and somehow make iOS 6 behave like iOS7 with status bars ?
You can't make iOS 6 status bar act like iOS 7 status bar they are completely different designs. iOS 7 uses a flat UI whilst iOS 6 doesn't. Have a read through the iOS 7 transition guide for a better understanding and how to handle the differences.
To be specific towards the Status bar here is the section of that document that tells you how to handle it.
Short Answer: No you can't.
iOS 6 SDK does not let you to control the status bar like iOS 7 does.
What you can do is adapt the size so it does not lose any structure in your actual layout
First you can define a constant to know when it is iOS 7 or not:
#define kIS_IOS_7 (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
then in your AppDelegate you can change the navigation bar appearence like this:
UIView *background = [[UIView alloc] init];
if (kIS_IOS_7) {
background.frame = CGRectMake(0, 0, 360, 64);
} else {
background.frame = CGRectMake(0, 0, 360, 44);
}
background.backgroundColor = [UIColor blackColor]; // choose your color or image
UIGraphicsBeginImageContext(background.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[background.layer renderInContext:context];
UIImage *backgroundImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[[UINavigationBar appearance] setBackgroundImage:backgroundImage
forBarMetrics:UIBarMetricsDefault];
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.
I'm working on an app that is ideally targeted all the way down to iOS 3.2. Still, I am developing it on Lion and with the latest 5 sdk. As far as I know, I am not using any sdk 5 specific features. But:
on any devices with iOS 5 or the simulator (set to v.5), the app works just fine.
on any devices with iOS 4.3 or below (and the same goes for the simulator set to v. 4.3), several things that have to do with view frames get misaligned.
For instance, here's 2 examples:
An activity indicator inside an alert view. Here's the code:
NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:fileRequest delegate:self];
if(urlConnection)
{
uistatusDialog = [[UIAlertView alloc] initWithTitle:(description ? NSLocalizedString(description, nil) : NSLocalizedString(#"Downloading", nil))
message:nil
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:nil];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
[indicator startAnimating];
[uistatusDialog addSubview: indicator];
[uistatusDialog show];
[indicator release];
And here are screenshots for both simulators:iOS 5: correct
iOS 4.3: misaligned
Similar things are happening with labels for which I set frames through [UILabel alloc]initWithFrame:CGRectMake(...].
This code, for instance:
UITableViewCell * cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:reuseIndentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleGray;
UILabel* mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(70, 0, 0, 20)] autorelease];
mainLabel.font = [UIFont boldSystemFontOfSize:(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 18 : 12)];
mainLabel.textAlignment = UITextAlignmentLeft;
mainLabel.textColor = [UIColor blackColor];
mainLabel.backgroundColor = [UIColor clearColor];
mainLabel.autoresizingMask = (UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleRightMargin);
//mainLabel.adjustsFontSizeToFitWidth = YES;
mainLabel.tag = MAINLABEL_TAG;
Aligns just fine in iOS5, both for the simulators and devices. But in 4.3 it doesn't.
I can only think that the local coordinate frame changed from one SDK to the next?
Any help is greatly appreciated!
EDIT: Just to pull it off for now, I did end up replacing all instances of CGRectMake(x,y,w,h) with something along the lines of (assuming x,y,w,h are the ones I would have used for CGRectMake):
CGrect refFrame = superview.frame;
refFrame.origin.x += x;
refFrame.origin.y += y;
refFrame.size.w = w;
refFrame.size.h = h;
theObjInQuestion.frame = refFrame;
So essentially, looks like a different frame of reference is being used between SDK 5 and 4.3 at least...
I had a similar issue with one UIImageView in our app being displaced downwards about 100pts on screen, appearing to be displaced by other content that should have been floating on top of the UIImageView (though that may have been a coincidence).
The 'solution' I found in our case was to disable auto-sizing for the top positioning attribute for the UIImageView in IB, by clicking on the red I in the Autosizing display on the Size Inspector in Interface Builder. I call this a 'solution' rather than a solution because it remains unclear to me why this was a problem at all, and why this only occurred for this one view and only in iOS 5.
I also found that repositioning this view up, or down, prevented it from being displaced. It was only when it was aligned with the top edge of its parent view that the issue occurred.
My conclusion was it was probably a bug in iOS 5, rather than a new intended or more strict behavior, but I remain uncertain.
There are some major differences between 4 and 5, though I've only begun to figure them out. Something has changed in the coordinate systems, but precisely what I don't know.
I kinda suspect that the best/safest thing to do is to have two entirely different paths for calculating layout, until someone can figure out all of the "gotchas". That way the two versions can be "tuned" separately.