模态视图1-底部弹出分享按钮

本文介绍了一个iOS应用中的分享界面布局实现方法,使用第三方库SDAutoLayout进行适配,并详细展示了如何通过Objective-C创建一个可自适应不同屏幕尺寸的分享界面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目中加了功能,分享进微信微博什么的,就写了分享界面

!!里面布局用的第三方SDAutoLayout,网上一搜就能找到

//####################################################################################################
//######                               分割线.h文件                                       ############
//####################################################################################################

#import 

@protocol ShareModalViewButtonDelegate 

-(void)clickShareButtonWithTag:(NSInteger)tag;  //在实现代理的地方,按照tag对应操作,比如0对应微信,1对应朋友圈这样的

@end


@interface ShareModalViewController : UIViewController

@property(nonatomic,weak)iddelegate;

@property(nonatomic,strong) NSArray *buttonImages;  //图片名称数组,对应着顺序生成按钮
                                                    //每四个一行,如果有五个按钮,会自动适应尺寸,变为两行显示
@property(nonatomic,strong) NSArray *buttonTitles;  //按钮titles,按图片对应顺序

@end

//####################################################################################################
//######                               分割线.m文件                                       ############
//####################################################################################################

#import "ShareModalViewController.h"

//设定按钮标记基数
#define ShareButtonTagBase 161118

@interface ShareModalViewController (){
}

@property(nonatomic,strong) UIView *buttonsView;   //按钮部分视图
@property(nonatomic,strong) UIView *backView;   //黑色透明蒙板视图

@property(nonatomic,assign) NSInteger buttonsViewEdge;  //UI尺寸,根据设备设定:
@property(nonatomic,assign) NSInteger buttonW;        
@property(nonatomic,assign) NSInteger buttonH;
@property(nonatomic,assign) NSInteger gapX;
@property(nonatomic,assign) NSInteger gapY;
@property(nonatomic,assign) NSInteger buttonsViewHeight;
@property(nonatomic,assign) NSInteger backButtonHeight;
@property(nonatomic,assign) NSInteger buttonTitleFontSize;

@end

@implementation ShareModalViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    if(MainScreenWidth>370){  //根据屏幕尺寸设置尺寸参数,这算是一种比较二的做法。。
        _buttonsViewEdge=20;
        _buttonW=70;
        _buttonH=90;
        _gapX=(MainScreenWidth-_buttonsViewEdge*2-_buttonW*4)/3;
        _gapY=10;
        _backButtonHeight=45;
        _buttonTitleFontSize=15;
        _buttonsViewHeight=_buttonsViewEdge*2+_gapY+_buttonH*2+_backButtonHeight;
    }else if(MainScreenWidth>300){
        _buttonsViewEdge=15;
        _buttonW=60;
        _buttonH=75;
        _gapX=(MainScreenWidth-_buttonsViewEdge*2-_buttonW*4)/3;
        _gapY=10;
        _backButtonHeight=38;
        _buttonTitleFontSize=12;
        _buttonsViewHeight=_buttonsViewEdge*2+_gapY+_buttonH*2+_backButtonHeight;
    }
    [self createUI];   //创建界面
}

//创建UI
-(void)createUI{
    
    //背景蒙黑视图
    _backView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    _backView.backgroundColor=[UIColor blackColor];
    _backView.alpha=0;
    [self.view addSubview:_backView];
    UITapGestureRecognizer *tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(back)];
    [_backView addGestureRecognizer:tapGesture];
    
    //按钮集合View-用来添加所有按钮
    _buttonsView=[[UIView alloc]initWithFrame:CGRectMake(0, MainScreenHeight, MainScreenWidth,_buttonsViewHeight )];
    _buttonsView.backgroundColor=UIColorFromRGB(0xF2F2F2, 1.0);
    [self.view addSubview:_buttonsView];
    
    
    /********批量生成按钮*********
     *
     */
    NSInteger buttonNUM=[self.buttonImages count];  //按钮的总数量
    
    for(NSInteger num=0;num

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值