📜 ⬆️ ⬇️

What's wrong with the display of currency symbols in iOS

In June 2016, the application ILE de Bote appeared in the App Store. A client asked us to use the Carisma font. It does not apply to the system fonts of the iOS platform, which can be understood after trying to find it here . While working on the application, I noted that currency symbols falling in the range from U + 20B6 (symbol of tour livre) to U + 20BE (symbol of Georgian lari) and typed in a font that is not included in the number of system ones, reduce application performance. The symbol of the ruble - just out of the specified range.

Find the differences:


')
The captain gets in touch
The screen on the right lags. This is noticeable in terms of CPU utilization.

Let's discuss this.

We will understand in more detail, in which situations everything slows down the performance. To do this, we divide the representation of the line with the currency symbol into its constituent parts:

  1. The text can be contained in the following entities: UILabel, UITextView and UITextField
  2. These entities can use the normal NSString and the attributed NSAttributedString
  3. For a string, we can get the ruble symbol in one of three ways:

    1. Using HTML:

      NSString *htmlString = @"<p>500 ₽</p> "; self.string = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil]; 

    2. Using unicode:

       self.string = [[NSAttributedString alloc] initWithString: @"500 \u20BD"]; 

    3. Using number formatter:

       NSNumberFormatter * numberFormatter = [[NSNumberFormatter alloc] init]; [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; [numberFormatter setCurrencyCode:@"RUB"]; [numberFormatter setMaximumFractionDigits:0]; self.string = [[NSAttributedString alloc] initWithString:[numberFormatter stringFromNumber:@500]]; 

When I started to combine entities, I found that the following combinations reduce performance:

  1. UILabel, string type: attributed, methods for getting a character: 2 or 3
  2. UITextView, string type: any, character retrieval methods: any
  3. UITextField, string type: any, character retrieval methods: any

The experiment was to measure the load on the processor when scrolling through the list, the elements of which contained the symbol of the ruble. The average processor load for a normal state did not exceed 10%, and if there was a problem, the load fluctuated around 30-80%, which can be seen on gifs.


The picture outlines the symbols with which the described problem is observed.

In order for the application to behave normally, you should avoid those combinations that I identified, or use the system font San Francisco for the currency symbols, as well as fonts from the Helvetica Neue family. But these are the minimum requirements. The true reason for the increase in the load for me remains a mystery, and if someone understands the essence of the question - share your thoughts in the comments.

Source: https://habr.com/ru/post/312294/


All Articles