自定义系统分享顶部UI

2021-12-22  本文已影响0人  田小北北

自定义系统分享ShareSheet:https://blog.csdn.net/lg767201403/article/details/105269610

//
//  MyUIActivityViewController.m
//  ShareDemo
//
//  Created by longTT on 2021/12/21.
//

#import "MyUIActivityViewController.h"

@interface MyUIActivityViewController ()
@property (nonatomic, strong) UIView *topView;
@property (nonatomic, assign) int index;
@end

@implementation MyUIActivityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self findSubViewsInView:self.view];
    /*
     1、顶部分隔线之上高度固定 = 72
     2、右侧关闭按钮,父视图尺寸 = 43x44
     */
    //随便添加一个视图触发系统分享UI同步布局,不添加其他修改不生效
    self.topView = [[UIView alloc] init];
    self.topView.hidden = YES;
    [self.view addSubview:self.topView];
    self.topView.frame = CGRectMake(0, 0, self.view.frame.size.width - 44 - 8, 72);
}

- (void)findSubViewsInView:(UIView *)inView {
    for (UIView *subview in inView.subviews) {
        NSString *viewClass = NSStringFromClass([subview class]);
        if ([viewClass containsString:@"LPImage"]) {
            [self setupLeftIcon:subview];
        } else if ([viewClass containsString:@"LPTextView"]) {
            [self setupTitle:subview];
        }
        [self findSubViewsInView:subview];
    }
}

//设置顶部左边的icon
- (void)setupLeftIcon:(UIView *)inView {
    for (UIView *subview in inView.subviews) {
        if ([subview isKindOfClass:[UIImageView class]]) {
            UIImageView *iconView = (UIImageView *)subview;
            iconView.contentMode = UIViewContentModeScaleAspectFit;
            iconView.image = [UIImage imageNamed:@"Icon-6000"];
            break;
        }
    }
}

- (void)setupTitle:(UIView *)inView {
    for (UIView *subview in inView.subviews) {
        if ([subview isKindOfClass:[UILabel class]]) {
            UILabel *label = (UILabel *)subview;
            if (self.index == 0) {
                //标题
                label.text = @"我是大标题";
                label.font = [UIFont systemFontOfSize:19];
                label.textColor = [UIColor redColor];
            } else if (self.index == 1) {
                //副标题
                label.text = @"我是副标题啦啦啦啦啦啦啦";
                label.font = [UIFont systemFontOfSize:12];
                label.textColor = [UIColor blueColor];
            }
            self.index++;
            break;
        }
    }
}

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    [self findSubViewsInView:self.view];
}

@end

调用部分
NSMutableArray *activityItems = [[NSMutableArray alloc]init];
[activityItems addObject:@"🏠🏠🏠🏠🏠🏠🏠🏠"];//分享内容
[activityItems addObject:@"www.baidu.comwww]; //分享地址
UIImage *image = [UIImage imageNamed:@"1111.jpg"];//分享图片
[activityItems addObject:image];
MyUIActivityViewController *activityViewController = [[MyUIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
UIActivityViewControllerCompletionWithItemsHandler myBlock = ^(NSString *activityType, BOOL  completed,NSArray *returnedItems,NSError *activityError) {
    };
activityViewController.completionWithItemsHandler = myBlock;
[self presentViewController:activityViewController animated:YES completion:nil];
上一篇下一篇

猜你喜欢

热点阅读