富贵资源网 Design By www.hznty.com
首先来看看实现的效果图
下面话不多说,以下是实现的示例代码
#import <UIKit/UIKit.h> typedef void(^AlertResult)(NSInteger index); @interface XLAlertView : UIView @property (nonatomic,copy) AlertResult resultIndex; - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message sureBtn:(NSString *)sureTitle cancleBtn:(NSString *)cancleTitle; - (void)showXLAlertView; @end
#import "XLAlertView.h" ///alertView 宽 #define AlertW 280 ///各个栏目之间的距离 #define XLSpace 10.0 @interface XLAlertView() //弹窗 @property (nonatomic,retain) UIView *alertView; //title @property (nonatomic,retain) UILabel *titleLbl; //内容 @property (nonatomic,retain) UILabel *msgLbl; //确认按钮 @property (nonatomic,retain) UIButton *sureBtn; //取消按钮 @property (nonatomic,retain) UIButton *cancleBtn; //横线线 @property (nonatomic,retain) UIView *lineView; //竖线 @property (nonatomic,retain) UIView *verLineView; @end @implementation XLAlertView - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message sureBtn:(NSString *)sureTitle cancleBtn:(NSString *)cancleTitle { if (self == [super init]) { self.frame = [UIScreen mainScreen].bounds; self.backgroundColor = [UIColor colorWithWhite:0.8 alpha:0.6]; self.alertView = [[UIView alloc] init]; self.alertView.backgroundColor = [UIColor whiteColor]; self.alertView.layer.cornerRadius = 5.0; self.alertView.frame = CGRectMake(0, 0, AlertW, 100); self.alertView.layer.position = self.center; if (title) { self.titleLbl = [self GetAdaptiveLable:CGRectMake(2*XLSpace, 2*XLSpace, AlertW-4*XLSpace, 20) AndText:title andIsTitle:YES]; self.titleLbl.textAlignment = NSTextAlignmentCenter; [self.alertView addSubview:self.titleLbl]; CGFloat titleW = self.titleLbl.bounds.size.width; CGFloat titleH = self.titleLbl.bounds.size.height; self.titleLbl.frame = CGRectMake((AlertW-titleW)/2, 2*XLSpace, titleW, titleH); } if (message) { self.msgLbl = [self GetAdaptiveLable:CGRectMake(XLSpace, CGRectGetMaxY(self.titleLbl.frame)+XLSpace, AlertW-2*XLSpace, 20) AndText:message andIsTitle:NO]; self.msgLbl.textAlignment = NSTextAlignmentCenter; [self.alertView addSubview:self.msgLbl]; CGFloat msgW = self.msgLbl.bounds.size.width; CGFloat msgH = self.msgLbl.bounds.size.height; self.msgLbl.frame = self.titleLbl"htmlcode">XLAlertView *xlAlertView = [[XLAlertView alloc] initWithTitle:@"自定义UIAlertView" message:@"不喜勿喷,大神多多指导。不胜感激" sureBtn:@"确认" cancleBtn:@"取消"]; xlAlertView.resultIndex = ^(NSInteger index){ //回调---处理一系列动作 }; [xlAlertView showXLAlertView];总结
以上就是这篇文章的全部内容了,希望本文的内容对各位iOS开发们能有所帮助,如果有疑问大家可以留言交流,谢谢大家对的支持。
富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com
暂无评论...