I am trying to make my app's storyboard universal for all Apple devices. I am having an issue with auto layout for some of my views. I am considering making a storyboard for each device since I think it will look better in the end, since I would be able to size my fonts and buttons differently for each type of screen.
What would you guys recommend I do?
Thanks
A good approach would be to use autolayouts and size classes. This approach would allow you to create only single storyboard for both iPhone and iPad. And you can easily size your fonts for different devices and also make buttons/views position/size differently for different screen sizes using size classes.
You should use size classes in which "any width , any height " is best for all layouts .
AFIK you can't just use size classes to determine the screen size and then set font sizes based on that. As can be seen when you edit in Storyboards, you can set the font sizes for specific size classes eg. compact, regular etc. but not iPhone 5, 6 or 6+. If you are wanting different font sizes for different screen sizes you could use UIAppearance to style your text elements in a centralised way or create IBOutlets to the UI elements and set the font size or other properties as required. With either of these you may still need to check the screen size with something like this:
switch UIScreen.mainScreen().bounds.size.width{
case kIphone6PlusWidth:
label.font = label.font.fontWithSize(20)
case kIphone6Width:
label.font = label.font.fontWithSize(18)
default:
label.font = label.font.fontWithSize(14)
}
Alternatively, separate storyboards for each will give you customisability but will lead to a fair amount of duplication with laying out the UI elements in different storyboards.
Related
I'm trying to get my font sizes to scale with the change of system wide (via iOS Settings), but I am only able to get this functionality if I set Text Style to Body, etc in the Interface Builder.
I guess a way to do it could be to get the system font then factor that up a bit to get a new font-size to use:
let bodyFont = UIFont.preferredFontForTextStyle(UIFontTextStyleBody)
label.font = UIFont(descriptor: bodyFont.fontDescriptor(), size: bodyFont.pointSize * 1.2)
But is there a better way, because this feels wrong.
And is there a way to get notified when system font size change?
you need to listen to this notification: UIContentSizeCategoryDidChangeNotification
If you wanted to further increase those sizes, then you can do what you have suggested. Just be careful if the user chooses the really large font sizes in accessibility settings, as your fonts would be even bigger then.
I've been using the constraints for all objects to be aligned with each of the different screen sizes, but I want to manually set each one.
How can I manually adjust the size and location of objects on each screen size?
You can create storyboards for different sizes and load them; you can also set outlets for those constraints and set their constants.
Nevertheless, I would advise you to keep them all in one storyboard and try to adapt the autolayout to make it work for every size.
Tip: add a another navigation tab and select preview mode on this one (on storyboard). This way you will be able to see how the constraints behave in different sizes.
I've been looking at answers and documentation but can't find anything on this topic. I'm fairly new to IOS development, so hopefully this question is relevant for here.
I have a TableView where user swipes right on a cell and font size of the label increases. However, in order to make it according to design specs I would also need to increase font weight. This is what I currently use:
self.infoLabel.font = [UIFont fontWithName:self.textLabel.font.familyName size:20 + 20*_intensityPercentage];
Other methods I've looked at seem to only switch bold on/off, however I'd need to adjust it continously.
Another problem with TableViewCell I'm facing is that UILabel would become blurier with left swipe. Is that even possible to do?
Any help is much appreciated. Thank you!
Per Is there a medium weight font between -systemFontOfSize: and -boldSystemFontOfSize:?, iOS doesn't support dynamic font weight. But since many fonts that ship with iOS ship with 3 or more "weights" within the font family you likely have more control available than normal / bold. For example, you might be able to dynamically rotate through HelveticaNeue-UltraLight to HelveticaNeue-Light to HelveticaNeue to HelveticaNeue-Medium to HelveticaNeue-Bold.
Check out http://www.iosfonts.com for a good dump of what fonts and weights are available to different versions of iOS.
As i am working on an application which i need to develop in iPhone4/iPhone5/iPad. Can somebody tell me complete flow or Tutorial link to make the application compatible with all above platforms. There is a way of auto resizing and auto layout and i don't know how to use this?
According to me, I have two ways to implement this concept, Either by taking three different xib files for iPhone4/iPhone4s/iPhone5 or by setting the frame of the layouts pro grammatically after detecting the device.
Can you please tell me any other easy way for implementing this concept?
If you want to make your design compatible/migrated to iPhone5, please read these documents and questions:-
Lower Version apps compatible to iPhone 5
Guide Lines
Helping Question
It'll help you to achieve the goal.
Thanks.
If you don't want to use three different xib files for each, then you have to try this method
CGRect screenBounds = [[UIScreen mainScreen] bounds];
after this set your code according to device
if (screenBounds.size.height == 568)
{
// code for 4-inch screen
}
else if (screenBounds.size.height == 1024)
{
//code for ipad
}
else
{
// code for 3.5-inch screen
}
Is there any shortcut way?
That depends a bit on how you want your app to look and work. If you want the UI to be about the same regardless of screen size, then you might be able to get away with merely adjusting the sizes and positions of the different elements. Far more often, though, you'll want to use the available screen space to best advantage, so you'll have more and different content on a larger screen than you do on a smaller screen. In these cases, there really isn't any shortcut: you need to think carefully about how the app will work on each device.
Even if you do want essentially the same UI on all devices, there's still a lot to be said for using separate .xib files for each. Once you know which UI elements you want on the screen, putting together a .xib is pretty quick and easy. Having separate .xibs lets you fine tune the UI for each size. In reality, you'll often need only two .xibs for each screen -- an iPad-sized .xib and an iPhone-sized one. The autolayout system is more than powerful enough to let you adjust between iPhone 4 and iPhone 5 sized screens.
The app I'm currently working on has a huge number of views. Some are webviews and some normal UIViews, with a ton of subviews. Now that the iPhone 5 has come out, how can I most efficiently change the frame size of the entire app to support both 4-inch and 3.5 inch devices? I certainly could use a whole bunch of if-else statements and layout several frame sizes for each view, but what's the best, most efficient way this could be done?
Most efficient way is to use one of the provided layouting mechanisms:
Autoresizing – Each UIView has property autoresizingMask and by setting it to one or many values (using | operator) you tell the view how to behave when the size of its superview changes. Elementary options:
UIViewAutoresizingFlexible...
...Width
...Height
...LeftMargin
...RightMargin
...TopMargin
...BottomMargin
Auto Layout – New in iOS 6, it provides more complex (very complicated) mechanism of relations between view attributes. Basicaly it is a superset of autoresizing and there are some long docs for it. I don't recommend it to you.