iOS 9 Adaptable font sizes? - swift

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.

Related

iOS9 Storyboards Auto Layout

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.

iOS: Dynamically change font weight and bluriness of UILabel

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.

iPhone -- getting the adjusted font size of a UITextField

I have a UITextField with the adjustsFontSizeToFitWidth property set to YES. I want to get ahold of the current (adjusted) font size. Is that possible?
If not, getting ahold of the actual width of the text (in the adjusted size) would be almost as good.
In the adjusted size, the width of the text would be the same as the width of the text field.
I don't think it's possible, but it should not be too difficult to write your own class.
Here's a small snippet/extension I wrote down to handle this.
http://swiftstub.com/134886004/

Iphone UI Size / Layout Resource?

Is anyone aware of a website or download to reference for the size of UI elements or standard iphone interface stuff? What I mean is something that gives the height of elements like the status bar, tab bar, navigation bar, default tableviewcell height (and such things as width of accessory view, indentation, etc), default icon sizes, default font sizes for UI elements (if they need to be mimicked, for instance), etc etc etc.
It's amazing how many times I have to go back to find a reference or estimate the size and position of a standard element. It seems like it would be an invaluable resource that could fit on a printed page or two.
Found most of what I was looking for here:
http://www.idev101.com/code/User_Interface/sizes.html
This website has a PSD with the iPhone UI elements that might give you the exact information you are looking for.
http://www.teehanlax.com/blog/2009/06/18/iphone-gui-psd-30/

large scrollable "something" with TTStyledText in it

im searching for a solution of the following problem:
i got a "larger" XHTML string that i want to display in an area that is scrollable.
I already used TTStyledTextLabel for a small text-caption and it works pretty well.
But now i want display it more like a UITextView that scrolls or a UIScrollView with my TTStyled Content in it. i think TTStyledTextLabel isnt the right thing to view such a large (with large i mean about 900px height) content.
i need a TTStyledTextView, or something like that. Does something exist? How to work with it. My Content has a variable length so i cannot setup a UIScrollView with a TTStyledTextLabel in it.
Any hints for me ?
Thanks!
You can determine the height needed to display the whole XHTML string by doing this:
htmlLabel.text = [TTStyledText textFromXHTML:htmlText];
[htmlLabel sizeToFit];
CGFloat height=htmlLabel.height;
I do this to create dynamic table cells that include these labels. You can use this height to set the contentSize of a parent scrollview.
You might however run into problems if your view is higher than 1024pixels on iPhone OS 2.x:
Note: Prior to iPhone OS 3.0, UIView instances may have a maximum height and width of 1024 x 1024. In iPhone OS 3.0 and later, views are no longer restricted to this maximum size but are still limited by the amount of memory they consume. Therefore, it is in your best interests to keep view sizes as small as possible. Regardless of which version of iPhone OS is running, you should consider using a CATiledLayer object if you need to create views larger than 1024 x 1024 in size.