Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Using icon font in iOS

Using icon font in iOS

2013/04/21 在 iOScon 上分享的keynote。

Pride Chung

April 21, 2013
Tweet

Other Decks in Programming

Transcript

  1. ! static dispatch_once_t onceToken; ! dispatch_once(&onceToken, ^{ ! ! NSURL

    * url = [[NSBundle mainBundle] URLForResource:@"FontAwesome" withExtension:@"otf"]; ! ! CGDataProviderRef fontDataProvider = CGDataProviderCreateWithURL((__bridge CFURLRef)url); ! ! CGFontRef newFont = CGFontCreateWithDataProvider(fontDataProvider); ! ! CGDataProviderRelease(fontDataProvider); ! ! CFErrorRef error; ! ! CTFontManagerRegisterGraphicsFont(newFont, &error); ! ! CGFontRelease(newFont); ! }); ! ! UIFont *font = [UIFont fontWithName:@"FontAwesome" size:size]; 运⾏行时注册 在项⺫⽬目的Info.plist中注册 或者 13年4月21⽇日星期⽇日
  2. ! UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 45, 45)];

    ! label.font = [UIFont fontWithName:@"FontAwesome" size:45]; ! label.text = @"\uf09b"; 13年4月21⽇日星期⽇日