forked from chrfalch/NControl.Controls
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNControls.cs
More file actions
45 lines (40 loc) · 1.2 KB
/
NControls.cs
File metadata and controls
45 lines (40 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using Xamarin.Forms;
using Foundation;
using CoreGraphics;
using CoreText;
using System.IO;
using UIKit;
using System.Collections.Generic;
namespace NControl.Controls.iOS
{
/// <summary>
/// NControls.
/// </summary>
public static class NControls
{
/// <summary>
/// Init this instance to
/// </summary>
public static void Init()
{
NControl.Controls.FontLoader.LoadFonts (AppDomain.CurrentDomain.GetAssemblies(), (fontName, s) => {
var data = new byte[s.Length];
s.Read (data, 0, data.Length);
var dataProvider = new CGDataProvider (data, 0, data.Length);
var familyNames = UIFont.FamilyNames; //fixes app freeze in some cases: https://alpha.app.net/jaredsinclair/post/18555292
var cgFont = CGFont.CreateFromProvider (dataProvider);
NSError error;
var registered = CTFontManager.RegisterGraphicsFont(cgFont, out error);
if (!registered)
{
// If the error code is 105 then the font we are trying to register is already registered
// We will not report this as an error.
if (error.Code != 105)
throw new ArgumentException("Error registering: " + fontName +
" (" + error.LocalizedDescription + ")");
}
});
}
}
}