登录 立即注册
金钱:

Code4App-iOS开发-iOS 开源代码库-iOS代码实例搜索-iOS特效示例-iOS代码例子下载-Code4App.com

自定义UIActionSheet

[复制链接]
来自: EverStar 分类: iOS精品源码 上传时间: 2016-4-11 16:02:30

项目介绍:

自定义UIActionSheet

主要实现代码:
[Objective-C] 查看源文件 复制代码
//
#import "MessagePopView.h"
#define SCREEN_WIDTH   ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT  ([UIScreen mainScreen].bounds.size.height)
@interface MessagePopView ()

@property (strong, nonatomic)UIImageView *imgView;
@property (strong, nonatomic)UIImageView *imgViewMessage;
@property (strong, nonatomic)UILabel *backgroundLabel;
@property (strong, nonatomic)UIView *contentView;
@property (nonatomic, strong)UIButton *clearMessageBtn;
@property (nonatomic, strong)UIButton *cancelBtn;

@end

@implementation MessagePopView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self drawView];
    }
    return self;
}

- (void)drawView{
    
    //半透明背景
    self.imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"show_pop_view_bk"]];
    self.imgView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    self.imgView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hidePopView)];//添加手势,点击隐藏
    [self.imgView addGestureRecognizer:tapGesture];
    [self addSubview:self.imgView];
    
    
    //弹层容器视图
    self.contentView = [[UIView alloc]init];
    self.contentView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 100);
    
    //弹层背景图
    self.imgViewMessage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"show_manage_pop_view_bk"]];
    self.imgViewMessage.frame = CGRectMake(0, 0, SCREEN_WIDTH, 100);
    self.imgViewMessage.userInteractionEnabled = YES;
    [self.contentView addSubview:self.imgViewMessage];
    
    self.clearMessageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.clearMessageBtn.frame = CGRectMake(0, 0, SCREEN_WIDTH, 45);
    self.clearMessageBtn.backgroundColor = [UIColor whiteColor];
    [self.clearMessageBtn setTitle:@"确认" forState:UIControlStateNormal];
    [self.clearMessageBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.clearMessageBtn addTarget:self action:@selector(MessageClick) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.clearMessageBtn];
    
    self.cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.cancelBtn.frame = CGRectMake(0, 55, SCREEN_WIDTH, 45);
    self.cancelBtn.backgroundColor = [UIColor whiteColor];
    [self.cancelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [self.cancelBtn addTarget:self action:@selector(hidePopView) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.cancelBtn];
   
    [self.imgView addSubview:self.contentView];
}

//点击确认的事件
- (void)MessageClick{
    /**
     *  这里添加其他操作
     */
    [self hidePopView];
}

//隐藏弹层
-(void) hidePopView
{
    [UIView animateWithDuration:0.3 animations:^{
        self.contentView.frame = CGRectMake(0.0f, SCREEN_HEIGHT + 100 , self.frame.size.width, self.contentView.frame.size.height );
    } completion:^(BOOL finished) {
        self.hidden = YES;
        [self removeFromSuperview];
    }];
    
}
//显示弹层
-(void) showPopView
{
    [UIView animateWithDuration:0.5 animations:^{
        self.hidden = NO;
        self.contentView.frame = CGRectMake(0.0f,  SCREEN_HEIGHT - 100, self.frame.size.width, self.contentView.frame.size.height);
    }];
    self.imgView.hidden = NO;
}
@end



DEMO下载:

相关源码推荐:

我来说两句
*滑动验证:
所有评论(23)
402016082 2016-6-8 15:12:05
学习学习!
回复
ls5610301 2016-6-12 11:14:48
虽不明,但觉厉!
回复
huyauncoco 2016-7-1 16:44:06
我只是路过打酱油的。
回复
rocky.golden 2016-7-3 12:47:32
我只是路过打酱油的。
回复
275199758 2016-7-4 19:25:56
我只是路过打酱油的。
回复
LiuBing_ios 2016-7-9 15:00:39
感谢分享,Code4App有你更精彩:)
回复
code4app热心网友 2016-7-26 16:06:11
很给力,Code4App有你更精彩!
回复
code4app热心网友 2016-7-26 16:06:35
楼主用心了,内容非常精彩。
回复
code4app热心网友 2016-8-2 13:27:11
楼主用心了,内容非常精彩。
回复
123下一页
提取码:  下载次数:34 状态:已购或VIP 售价:0(原价:10)金钱 下载权限:初级码农 
552 1 34
联系我们
首页/微信公众账号投稿

帖子代码编辑/版权问题

QQ:435399051,742864542

如何获得代码达人称号?

代码贡献英雄榜
用户名 下载数
通过邮件订阅最新 Code4App 信息
上一条 /4 下一条
联系我们
关闭
合作电话:
13802416937
Email:
435399051@qq.com
商务市场合作/投稿
问题反馈及帮助
联系我们

广告投放| Github|申请友链|手机版|Code4App ( 粤ICP备15117877号-1 )

快速回复 返回顶部 返回列表