<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      iOS UIFont 的學習與使用

      通常,我們使用字體 都是系統默認的字體. 有時候 從閱讀體驗,美觀度 設計師都會考慮用一些 更高大尚的字體. 系統字體庫 給英文 各種style的發揮空間很大,但是 中文則不然. 

      但是蘋果 給使用中文的字體的開發者提供了 動態下載字體庫的福利,這個真是好,并且下載到/private/var/mobile/Library/Assets/com_apple_MobileAsset_Font/  這樣不會增加app本身的大小. 不失為一種好的選擇.

      前提:  你首先 要知道 你要使用的字體的官方名字, 用這個名字 當索引下載.

      官方竟然有文檔和demo 真是方便的不要不要的:

      https://developer.apple.com/library/ios/samplecode/DownloadFont/Listings/DownloadFont_ViewController_m.html

       操作基本步驟

      1. 首先判斷 是否有這種字體 無則用默認的

      (如果 要使用一些 iOS8,iOS9才有的字體 一定要考慮低版本用戶的情況,會閃退,在 font 類別里面也要做預判斷,沒有這個字體 就用默認的唄)

      + (UIFont *)normalHfFontWithSize: (CGFloat)fontSize {
      
          return [UIFont isFontDownloaded:@"FZLTXHK--GBK1-0"] ? [UIFont fontWithName:@"FZLTXHK--GBK1-0" size:fontSize] : [UIFont systemFontWithSize:fontSize];
      }
      
      + (BOOL)isFontDownloaded:(NSString *)fontName {
          UIFont* aFont = [UIFont fontWithName:fontName size:12.0];
          if (aFont && ([aFont.fontName compare:fontName] == NSOrderedSame
                        || [aFont.familyName compare:fontName] == NSOrderedSame)) {
              return YES;
          } else {
              return NO;
          }
      }

       2. 我的下載策略 是 打開應用 就在父線程里面 處理 需要的字體下載等事宜 , 也有人 是用再下載 ,看需求吧 

          Reachability *r = [Reachability reachabilityForInternetConnection];
          [r startNotifier];
          NetworkStatus netStatus = [r currentReachabilityStatus];
          
          NSArray *fonts = @[@"FZLTZHK--GBK1-0",@"FZLTXHK--GBK1-0"];
          
          for (NSString *font in fonts) {
              NSString *isFontAvailable = [[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"FontDownloaded%@",font]];
              if ((netStatus == ReachableViaWiFi && ![isFontAvailable isEqualToString:font]) || [isFontAvailable isEqualToString:font]) {
                  [UIFont downloadFont:font];
              }
          }

       


      + (void)downloadFont:(NSString *)fontName { UIFont* aFont = [UIFont fontWithName:fontName size:12.]; // If the font is already downloaded if (aFont && ([aFont.fontName compare:fontName] == NSOrderedSame || [aFont.familyName compare:fontName] == NSOrderedSame)) { // Go ahead and display the sample text. return; } // Create a dictionary with the font's PostScript name.

      NSMutableDictionary *attrs = [NSMutableDictionary dictionaryWithObjectsAndKeys:fontName, kCTFontNameAttribute, nil]; // Create a new font descriptor reference from the attributes dictionary. CTFontDescriptorRef desc = CTFontDescriptorCreateWithAttributes((__bridge CFDictionaryRef)attrs); // 將字體描述對象放到一個NSMutableArray中 NSMutableArray *descs = [NSMutableArray arrayWithCapacity:0]; [descs addObject:(__bridge id)desc]; CFRelease(desc); __block BOOL errorDuringDownload = NO; // Start processing the font descriptor.. // This function returns immediately, but can potentially take long time to process. // The progress is notified via the callback block of CTFontDescriptorProgressHandler type. // See CTFontDescriptor.h for the list of progress states and keys for progressParameter dictionary. CTFontDescriptorMatchFontDescriptorsWithProgressHandler( (__bridge CFArrayRef)descs, NULL, ^(CTFontDescriptorMatchingState state, CFDictionaryRef progressParameter) { NSString *errorMessage; DLog( @"state %d - %@", state, progressParameter); // double progressValue = [[(__bridge NSDictionary *)progressParameter objectForKey:(id)kCTFontDescriptorMatchingPercentage] doubleValue]; if (state == kCTFontDescriptorMatchingDidBegin) { dispatch_async( dispatch_get_main_queue(), ^ { DLog(@"Begin Matching"); }); } else if (state == kCTFontDescriptorMatchingDidFinish) { dispatch_async( dispatch_get_main_queue(), ^ { // Log the font URL in the console CTFontRef fontRef = CTFontCreateWithName((__bridge CFStringRef)fontName, 0., NULL); CFStringRef fontURL = CTFontCopyAttribute(fontRef, kCTFontURLAttribute); DLog(@"%@", (__bridge NSURL*)(fontURL)); CFRelease(fontURL); CFRelease(fontRef); if (!errorDuringDownload) { [[NSUserDefaults standardUserDefaults] setObject:fontName forKey:[NSString stringWithFormat:@"FontDownloaded%@",fontName]]; [[NSUserDefaults standardUserDefaults] synchronize]; DLog(@"%@ downloaded", fontName); } }); } else if (state == kCTFontDescriptorMatchingWillBeginDownloading) { dispatch_async( dispatch_get_main_queue(), ^ { DLog(@"Begin Downloading"); }); } else if (state == kCTFontDescriptorMatchingDidFinishDownloading) { dispatch_async( dispatch_get_main_queue(), ^ { DLog(@"Finish downloading");
      // 可以在這里修改UI控件的字體 }); }
      else if (state == kCTFontDescriptorMatchingDownloading) { dispatch_async( dispatch_get_main_queue(), ^ { //DLog(@"Downloading %.0f%% complete", progressValue); }); } else if (state == kCTFontDescriptorMatchingDidFailWithError) { // An error has occurred. // Get the error message NSError *error = [(__bridge NSDictionary *)progressParameter objectForKey:(id)kCTFontDescriptorMatchingError]; if (error != nil) { errorMessage = [error description]; } else { errorMessage = @"ERROR MESSAGE IS NOT AVAILABLE!"; } // Set our flag 設置標志 errorDuringDownload = YES; dispatch_async( dispatch_get_main_queue(), ^ { DLog(@"Download error: %@", errorMessage); }); } return (bool)YES; }); }

      妥妥的 滿足使用動態下載的字體需求

      備注:

      其他方法還有 使用字體資源文件(尾綴為.ttf或otf格式文件),上網上搜吧 講解 一堆 .

      但是這里存在的問題 1  需要把這個 .ttf文件 target到工程 不像 動態下載不增加 應用本身的大小 的特點

      其次是 如果沒有處理版權問題,這個就大發了 是吧... 

      看需求 正確使用 恰當的方法解決問題吧

       

      參考:

      http://www.awnlab.com/archives/2658.html

      posted on 2016-06-13 18:58  ACM_Someone like you  閱讀(2309)  評論(0)    收藏  舉報

      導航

      主站蜘蛛池模板: 精品av一区二区三区不卡| 在线亚洲午夜片av大片| 强行交换配乱婬bd| 亚洲av乱码一区二区| 精品亚洲精品日韩精品| 亚洲综合国产精品第一页| 国产精品天干天干综合网| 亚洲国产精品日韩在线| 成人国产精品中文字幕| 自拍视频在线观看三级| 九九热在线免费观看视频| 精品黄色av一区二区三区| 亚洲 日韩 国产 制服 在线| 免费看成人欧美片爱潮app| 99人中文字幕亚洲区三| 久久人与动人物a级毛片 | 亚洲人成网站77777在线观看| 亚洲欧美综合精品成| аⅴ天堂中文在线网| 正阳县| 亚洲精品一区二区三区蜜| 亚洲中文字幕人妻系列| 99热精品毛片全部国产无缓冲| 亚洲熟女乱色综一区二区| 97精品伊人久久大香线蕉APP | 综合色一色综合久久网| 性高湖久久久久久久久| 亚洲精品揄拍自拍首页一| 亚洲欧洲日产国无高清码图片| 亚洲精品成人久久久 | 国产成人a在线观看视频免费| 国产成人高清亚洲综合| 久久精品国产99国产精品| 亚洲三级香港三级久久| 亚洲午夜精品久久久久久抢| 亚洲午夜久久久久久噜噜噜| 兴和县| 亚洲精品国产第一区二区| 国产精品中文字幕免费| 亚洲欧美日产综合在线网| 高清破外女出血AV毛片|