Tracking and character spacing on iOS

Finally got to understand how to use the “tracking” value from the InDesign files I received for an app I’m working on. Thanks to this post from devsign, this is one more step to a pixel perfect label integration.

In tools like Photoshop and InDesign, tracking is the term that describes the relative amount of spacing between characters in a string of text.

A wonderful bit about tracking: pick a value, and your text will have that same visual style, regardless of the font size. It scales[…]

Source: http://www.devsign.co/notes/tracking-and-character-spacing

Open source projects should be more accessible to contributors

There are ton of developers out there, me included, who are looking for open source projects to help and improve their technical skills. It’s a good opportunity to dive into other people code, learn good practices and actually have code reviews from peers. Unfortunately, it’s often really hard to find a good project to actually contribute. And even then, it is difficult to know where to start and what you could actually do.

The project doesn’t work out of the box

The code can sometimes have a lot of dependencies and project developers didn’t take the time to write a “Getting started” note to help potential contributors to have a working copy of your project. Even when its there, it has to be up to date.

Project owner doesn’t explicitly say how contributors can help

What could potential others do to help in your project? That’s often unclear. They could find something to do by solving the issues, add features from a roadmap,  improve the tests coverage, everything is possible but usually hard to guess. Within issues, it’s usually better if they are tagged so it’s easy to see if it’s important or if it can be done without having a global knowledge of the project.

There is this post about the CONTRIBUTING.md file on Github, I like the idea and think it is a good place to gather all this thing that will help others to help!

I’m a really fan of the open source philosophy, I really would like to find more projects I could contribute 🙂

iOS and the status bar

Since iOS 7, there is this UIViewControllerBasedStatusBarAppearance or “View controller-based status bar appearance” option in Info.plist that aims to manage the way status bar appearance is set across the app.

Typical answers on Stack Overflow to questions regarding status bar text color not changing to white when using the UIApplication setStatusBarStyle: method or not disappearing when hiding will say:

Just set the “View controller-based status bar appearance” option to NO in your Info.plist.

That’s a mistake. By doing this, you are turning off the feature introduced in iOS 7. Even if I agree that this is convenient, I could not encourage you more to work with UIViewControllerBasedStatusBarAppearance set to YES.

Here are some things I learned trying to get it to work:

  1. The “Status bar style” and “Status bar is initially hidden” are still used during launch screen.
  2. If a view controller is not contained in a navigation controller and if you want to have a status bar with text colored in white, then you have to override the preferredStatusBarStyle method to say that you want the light content status bar style
  3. If you are using navigation controllers, the previous method is ignored so you should use [[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];, status bar style is automatically set light content in this case
  4. To hide status bar, there is also this “prefersStatusBarHidden” method that you can override
  5. The overridden methods are called when  your view controller is first displayed, but you can force iOS to update status bar settings by calling [self setNeedsStatusBarAppearanceUpdate]; at runtime

A good example of something you can’t achieve with UIViewControllerBasedStatusBarAppearance set to NO: is getting the status bar to white text color when opening a MFMailComposeViewController; even with status bar default color globally set, the status bar stays written in black. To bypass that, you must change the option value to YES, and you can, for instance, create a category like this one:

#import "MFMailComposeViewController+StatusBarStyle.h"
@implementation MFMailComposeViewController (StatusBarStyle)
#pragma mark - Status bar management
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}
- (UIViewController *)childViewControllerForStatusBarStyle
{
    return nil;
}
@end

Part of the credit goes to this post: https://coderwall.com/p/hitv1q/mastering-ios-7-uistatusbarstyle

The difference between line separator and paragraph separator

Did you know that there is a possible difference between line and paragraph separators with unicode characters?

This is very interesting when you are working with attributed strings. Basically, a \n is a paragraph separator (same as unicode character U+2029), lineSpacing doesn’t have any impact on this “line break“. You must use unicode line separator (U+2028) instead.

// Let's prepare our paragraph style attribute
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = 4.0f; // For line separators and automatic line breaks
paragraphStyle.paragraphSpacing = 20.0f; // For paragraph separators

// Now we can use it to create an attributed string that behave differently with line and paragraph separators
[[NSAttributedString alloc] initWithString:@"Hello, World!"
attributes:@{ NSParagraphStyleAttributeName: paragraphStyle }];

More information about this in Apple iOS documentation