2016-03-21 34 views
2

如何爲UIApplicationShortcutItem添加自定義圖像UIApplicationShortcutIcon?類似於照片UIApplicationShortcutItem在照片/消息應用程序中爲最近。由於所有圖標都是從一個自定義圖像創建一個圖標。提供的圖像命名將從應用程序的包中加載,並將被屏蔽以符合系統定義的圖標style.So我怎樣才能以編程方式獲得UIApplicationShortcutIcon的彩色圖像?如何將UIApplicationShortcutItem中的自定義圖像添加爲UIApplicationShortcutIcon?

回答

2

您可以從應用程序委託添加快捷圖標also.Here img_editProductimg_Classifieds在添加自定義圖像。 xcassests文件

- (void)shortcutsWithIcon 
{ 
    @try 
    { 
     UIApplicationShortcutIcon *icon1 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"img_editProduct"]; 
     UIApplicationShortcutIcon *icon2 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"img_Classifieds"]; 

     UIMutableApplicationShortcutItem *item1 = [[UIMutableApplicationShortcutItem alloc]initWithType:@"com.3dtouchApp.postAnItem" localizedTitle:@"Post an Item" localizedSubtitle:@"Add new product for sale" icon:icon1 userInfo:nil]; 
     UIMutableApplicationShortcutItem *item2 = [[UIMutableApplicationShortcutItem alloc]initWithType:@"com.3dtouchApp.LatestAds" localizedTitle:@"Latest Ads" localizedSubtitle:@"View top recent Ads" icon:icon2 userInfo:nil]; 
     NSArray *items = @[item2, item1]; 

     [UIApplication sharedApplication].shortcutItems = items; 
    } 
    @catch (NSException *exception) { 

    } 
} 


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    if (self.window.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) 
    { 
     [self shortcutsWithIcon]; 
     if ([item.type isEqualToString:@"com.3dtouchApp.postAnItem"]) 
     { 
      ***//Code for launch your screen*** 
     } 

     if ([item.type isEqualToString:@"com.3dtouchApp.LatestAds"]) 
     { 
      ***//code for launch your screen*** 
     } 
    } 
return YES; 
} 
0

做的不到位的模板圖標的使用表情符號。當文本右對齊時,Emojis無法正確對齊 。此外,emojis是全綵色, ,而模板圖標應該是單色的。您可以從許多系統提供的模板圖標中選擇 ,也可以創建一個 自定義模板圖標。有關圖標大小,填充, 和定位的詳細指導,請從 https://developer.apple.com/design/downloads/Quick-Action-Guides.zip下載主屏幕快速操作圖標模板。 要了解有關設計模板圖標的更多信息,請參閱模板圖標。

根據上述文字,我不認爲有沒有辦法顯示彩色圖標。可能是我們會在未來的更新。

相關問題