您的位置:首页 > 其它

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

2016-11-22 11:17 253 查看
项目中加了功能,分享进微信微博什么的,就写了分享界面

!!里面布局用的第三方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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: