首先来看看实现的效果图
下面话不多说,以下是实现的示例代码
#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.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 纯音入心系列纯音乐《天籁古筝》1CD[MP3][331MB]
- 男女对唱典藏天碟《发烧对唱·那个季节里的歌DSD》10CD[WAV]
- 群星2010-歌林精选辑[歌林][WAV+CUE]
- TrioZimbalist-PianoTriosofWeinberg,Auerbach,Dvorak(2024)[24-44,1]wav
- 群星.1992-滚石第一流台湾歌·12王牌大车拼【滚石】【WAV+CUE】
- 林子祥.1984-创作歌集【华纳】【WAV+CUE】
- 周汤豪.2010-周汤豪【华纳】【FLAC分轨】
- Mozart-TheStringQuintets-AmadeusQuartet,CecilAronowitz(2017)[24-44,1][WAV+CUE]
- JamesWilliamsDennisIrwin-Focus(2024,Red)[24-48]FLAC
- 藤泽麻衣《空みあげて》[WAV]
- 纯音入心系列纯音乐《中国古筝经典名曲》1CD[MP3][1.3GB]
- 纯音入心系列纯音乐《古筝新奏:岁月静好与筝语,细水流年与筝同》1CD[MP3][846.9MB]
- 670《脆弱敏感小女生》[320K/MP3][27.53MB]
- 曾琳.2011-好好爱我【南方】【WAV+CUE】
- 范晓萱.1995-RAIN【福茂】【WAV+CUE】