How to customize UI in ShareSDK

Note: our sharing menu can modify the background, icons, text, color, etc. in addition, you can customize the UI by yourself and write the interface in your own way. After writing, you can call the following sharing method without UI. In addition, our UI is also open source.

1, No UI sharing

#import <ShareSDK/ShareSDK.h> 
//Create shared parameters
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    [shareParams SSDKSetupShareParamsByText:@"Share content"
                                         images:images //Incoming pictures to share
                                            url:[NSURL URLWithString:@"http://mob.com"]
                                          title:@"Share title"
                                           type:SSDKContentTypeAuto];
 
    //Share
    [ShareSDK share:SSDKPlatformTypeSinaWeibo //Platform type of incoming share
         parameters:shareParams
    onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) { // Callback processing;
    }

2, Custom shared menu bar style

// Header file to be imported for pop-up sharing menu
#import <ShareSDK/ShareSDK.h> 
#import <ShareSDKUI/ShareSDK+SSUI.h>
// Customize the header file to be imported for sharing menu bar
#import <ShareSDKUI/SSUIShareActionSheetStyle.h>
#Customize the header file to be imported for share editing interface
#import <ShareSDKUI/SSUIEditorViewStyle.h>
 
    //1. Create shared parameters (required)
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    NSArray* imageArray = @[[UIImage imageNamed:@"Picture name.png"]];
   (Note: pictures must be in Xcode In the left directory, the name must be transferred correctly. If you want to share network pictures, you can do so iamge parameter images:@[@"http://mob.com/Assets/images/logo.png?v=20150320"])
    [shareParams SSDKSetupShareParamsByText:@"Share content"
                                     images:imageArray
                                        url:[NSURL URLWithString:@"http://mob.com"]
                                      title:@"Share title"
                                       type:SSDKContentTypeAuto];
 
    // Set shared menu bar style (not necessary)
    // Set background color of sharing menu
    [SSUIShareActionSheetStyle setActionSheetBackgroundColor:[UIColor colorWithRed:249/255.0 green:0/255.0 blue:12/255.0 alpha:0.5]];
    // Set share menu color
    [SSUIShareActionSheetStyle setActionSheetColor:[UIColor colorWithRed:21.0/255.0 green:21.0/255.0 blue:21.0/255.0 alpha:1.0]];
    // Set share menu - cancel button background color
    [SSUIShareActionSheetStyle setCancelButtonBackgroundColor:[UIColor colorWithRed:21.0/255.0 green:21.0/255.0 blue:21.0/255.0 alpha:1.0]];
    // Set the text color of the share menu - cancel button
    [SSUIShareActionSheetStyle setCancelButtonLabelColor:[UIColor blackColor]];
    // Set sharing menu - social platform text color
    [SSUIShareActionSheetStyle setItemNameColor:[UIColor whiteColor]];
    // Set sharing menu - social platform text font
    [SSUIShareActionSheetStyle setItemNameFont:[UIFont systemFontOfSize:10]];
   //Set the navigation bar color of sharing editing interface
   [SSUIEditorViewStyle setiPhoneNavigationBarBackgroundColor:[UIColor blackColor]];
  //Set editing interface Title Color
  [SSUIEditorViewStyle setTitleColor:[UIColor redColor]];
  //Set unpublish label text color
   [SSUIEditorViewStyle setCancelButtonLabelColor:[UIColor blueColor]];
    [SSUIEditorViewStyle setShareButtonLabelColor:[UIColor blueColor]];
   //Set the style of the status bar of the sharing editing interface
   [SSUIEditorViewStyle setStatusBarStyle:UIStatusBarStyleLightContent];
  //Set simple sharing menu style
    [SSUIShareActionSheetStyle setShareActionSheetStyle:ShareActionSheetStyleSimple];
    //2. Pop up the share SDK share menu
    [ShareSDK showShareActionSheet:view
                             items:nil
                       shareParams:shareParams
               onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) { ...... }

3, Skip shared editing interface

Set the pop-up sharing menu, and directly click the platform sharing in the menu (skip the sharing editing interface).

#import <ShareSDK/ShareSDK.h>
#import <ShareSDKUI/SSUIShareActionSheetController.h>
//First, construct the sharing parameters:
 NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
  [shareParams SSDKSetupShareParamsByText:@"Share content"
                                         images:@[[UIImage imageNamed:@"shareImg.png"]]
                                            url:[NSURL URLWithString:@"http://mob.com"]
                                          title:@"Share title"
                                           type:SSDKContentTypeAuto];
  //Some platforms need this method for client sharing, such as Weibo
  [shareParams SSDKEnableUseClientShare];
  //Call shared method
 SSUIShareActionSheetController *sheet = [ShareSDK showShareActionSheet:view
                                                                         items:nil
                                                                   shareParams:shareParams
                                                           onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
                                                               switch (state) {
                                                                   case SSDKResponseStateSuccess:
                                                                       NSLog(@"Share success!");
                                                                       break;
                                                                   case SSDKResponseStateFail:
                                                                       NSLog(@"Sharing failure%@",error);
                                                                       break;
                                                                   case SSDKResponseStateCancel:
                                                                       NSLog(@"Share cancelled");
                                                                       break;
                                                                   default:
                                                                       break;
                                                               }
                                                           }];
   //Deleting and adding platform samples
 [sheet.directSharePlatforms removeObject:@(SSDKPlatformTypeWechat)];(Default wechat, QQ,QQ The space is directly shared by the client. With this method, you can share the editing interface)
 [sheet.directSharePlatforms addObject:@(SSDKPlatformTypeSinaWeibo)];(After this method is added, you can directly click the options in the share menu to share without skipping the share editing interface.)

4, Hide wechat collection platform

  [ShareSDK registerActivePlatforms:@[
                            // Do not use wechat platform for initialization
                            //@(SSDKPlatformTypeWechat),
                            // Use wechat sub platform to initialize
                            @(SSDKPlatformSubTypeWechatSession),
                            @(SSDKPlatformSubTypeWechatTimeline)
                            ]
           onImport:^(SSDKPlatformType platformType)
           {
               switch (platformType)
                  {
                         case SSDKPlatformTypeWechat:
                             [ShareSDKConnector connectWeChat:[WXApi class]];
                             break;
                        default:
                             break;
                     }
 
                 }
          onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo)
          {
              switch (platformType)
              {
                   case SSDKPlatformTypeWechat:
                      [appInfo SSDKSetupWeChatByAppId:@"wx4868b35061f87885"
                                            appSecret:@"64020361b8ec4c99936c0e3999a9f249"];
                      break;
                   default:
                      break;
              }
          }];

5, (share menu) platform order customization

The UI (sharing menu) platform order customization provided by the ShareSDK.

    //share
    [ShareSDK showShareActionSheet:nil
                       //Pass the platform to be customized into the items parameter
                       items:@[@(SSDKPlatformTypeMail),
                               @(SSDKPlatformTypeSMS),
                               @(SSDKPlatformTypeCopy),
                               @(SSDKPlatformTypeFacebook),
                               @(SSDKPlatformTypeTwitter),
                               @(SSDKPlatformTypeWechat),
                               @(SSDKPlatformTypeQQ)]
                       shareParams:shareParams
               onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) { .......}];

6, Custom share menu item

If you want to add a button of your own on our share menu, handle the events you want to do as follows:

#import <ShareSDKUI/SSUIShareActionSheetCustomItem.h>
//Add a custom platform (not necessary)
    SSUIShareActionSheetCustomItem *item = [SSUIShareActionSheetCustomItem itemWithIcon:[UIImage imageNamed:@"Icon.png"]
                                                                                  label:@"custom"
                                                                                onClick:^{
 
                                                                                    //Customize the processing logic of item being clicked
                                                                                    NSLog(@"=== custom item Be clicked ===");
                                                                                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"custom item Be clicked"
                                                                                                                                        message:nil
                                                                                                                                       delegate:nil
                                                                                                                              cancelButtonTitle:@"Determine"
                                                                                                                              otherButtonTitles:nil];
                                                                                    [alertView show];
                                                                                }];
  NSArray * platforms =@[@(SSDKPlatformSubTypeQQFriend),@(SSDKPlatformSubTypeWechatSession),@(SSDKPlatformTypeTencentWeibo),item];
//Then pass the declared platforms object to the items parameter in the sharing method
 [ShareSDK showShareActionSheet:nil
                             items:platforms
                       shareParams:shareParams
               onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {}

 

 

Tags: xcode network SDK

Posted on Tue, 07 Jan 2020 06:30:05 -0500 by mr00047