关于ios自定义弹框
来源:互联网 发布:java语言和c语言 编辑:程序博客网 时间:2024/06/16 19:35
有时开发项目过程中系统弹框不是想要的效果,那么久需要自定义弹框。首先弹框继承与UIView。
如下代码:
#import <UIKit/UIKit.h>
typedefvoid (^AlertResult)(NSInteger index);
@interface PhoneView :UIView
@property(copy,nonatomic)AlertResult resultIndex;
@property(strong,nonatomic)UILabel*phone;
@property(strong,nonatomic)UILabel*workTime;
- (void)show;
#import "PhoneView.h"
#import "Header.h"
@interfacePhoneView ()
@property(strong,nonatomic)UIView*alterV;
@property(strong,nonatomic)UILabel*phoneTitle;
@property(strong,nonatomic)UILabel*timeTitle;
@property(strong,nonatomic)UIButton*call;
@property(strong,nonatomic)UIButton*cancel;
@end
@implementation PhoneView
-(instancetype)init{
if (self=[superinit]) {
float totalW=SCREEN_W-2*DIS;
float buttonW=(totalW-3*DIS)/2;
self.frame = [UIScreenmainScreen].bounds;
self.backgroundColor=[UIColorlightGrayColor];
self.alpha=0.6;
_alterV=[[UIViewalloc]initWithFrame:CGRectMake(0,0, totalW, 200)];
_alterV.backgroundColor=[UIColorwhiteColor];
_alterV.layer.cornerRadius=5;
[selfaddSubview:_alterV];
_phoneTitle=[[UILabelalloc]initWithFrame:CGRectMake(TAP,TAP, 80, 40)];
_phoneTitle.textColor=[UIColorlightGrayColor];
//[self.contentView addSubview:_title];
_phoneTitle.font=[UIFontsystemFontOfSize:18];
_phoneTitle.textAlignment=NSTextAlignmentLeft;
_phoneTitle.text=@"联系电话";
[_alterVaddSubview:_phoneTitle];
_phone=[[UILabelalloc]initWithFrame:CGRectMake(CGRectGetMaxX(_phoneTitle.frame)+TAP,TAP, totalW-3*TAP-CGRectGetWidth(_phoneTitle.frame),40)];
_phone.textColor=[UIColorblackColor];
//[self.contentView addSubview:_title];
_phone.font=[UIFontsystemFontOfSize:18];
_phone.textAlignment=NSTextAlignmentLeft;
[_alterVaddSubview:_phone];
_timeTitle=[[UILabelalloc]initWithFrame:CGRectMake(CGRectGetMinX(_phoneTitle.frame),CGRectGetMaxY(_phoneTitle.frame)+TAP,CGRectGetWidth(_phoneTitle.frame),40)];
_timeTitle.textColor=[UIColorlightGrayColor];
//[self.contentView addSubview:_title];
_timeTitle.font=[UIFontsystemFontOfSize:18];
_timeTitle.textAlignment=NSTextAlignmentLeft;
_timeTitle.text=@"工作时间";
[_alterVaddSubview:_timeTitle];
_workTime=[[UILabelalloc]initWithFrame:CGRectMake(CGRectGetMaxX(_timeTitle.frame)+TAP,CGRectGetMaxY(_phoneTitle.frame)+TAP,CGRectGetWidth(_phone.frame),40)];
_workTime.textColor=[UIColorblackColor];
//[self.contentView addSubview:_title];
_workTime.font=[UIFontsystemFontOfSize:18];
_workTime.textAlignment=NSTextAlignmentLeft;
[_alterVaddSubview:_workTime];
UILabel*line=[[UILabelalloc]initWithFrame:CGRectMake(TAP,CGRectGetMaxY(_workTime.frame)+TAP, totalW, 10)];
line.text=@"--------------------------------";
line.textColor=[UIColorlightGrayColor];
[_alterVaddSubview:line];
_call=[UIButtonbuttonWithType:UIButtonTypeCustom];
_call.frame=CGRectMake(DIS, CGRectGetMaxY(line.frame)+TAP, buttonW,40);
_call.titleLabel.font=[UIFontsystemFontOfSize:18];
[_callsetTitleColor:[UIColorwhiteColor] forState:UIControlStateNormal];
[_callsetTitle:@"立即拨打"forState:UIControlStateNormal];
[_callsetBackgroundImage:[UIImageimageNamed:@"等级"]forState:UIControlStateNormal];
[_alterVaddSubview:_call];
[_calladdTarget:selfaction:@selector(callPhone:)forControlEvents:UIControlEventTouchUpInside];
_call.tag=99;
_cancel=[UIButtonbuttonWithType:UIButtonTypeCustom];
_cancel.frame=CGRectMake(CGRectGetMaxX(_call.frame)+DIS, CGRectGetMaxY(line.frame)+TAP, buttonW,40);
_cancel.titleLabel.font=[UIFontsystemFontOfSize:18];
[_cancelsetTitleColor:RGBA(209,167, 76, 1)forState:UIControlStateNormal];
[_cancelsetTitle:@"取消"forState:UIControlStateNormal];
_cancel.layer.borderWidth=2;
CGColorSpaceRef colorSpaceRef =CGColorSpaceCreateDeviceRGB();
CGColorRef color =CGColorCreate(colorSpaceRef, (CGFloat[]){0.8,0.7,0.3,1});
[_cancel.layersetBorderColor:color];
[_alterVaddSubview:_cancel];
[_canceladdTarget:selfaction:@selector(callPhone:)forControlEvents:UIControlEventTouchUpInside];
_cancel.tag=88;
_cancel.layer.cornerRadius=20;
}
returnself;
}
- (void)show{
UIWindow*root=[UIApplicationsharedApplication].keyWindow;
[root addSubview:self];
self.alterV.layer.position = self.center;
self.alterV.transform = CGAffineTransformMakeScale(0.90,0.90);
[UIViewanimateWithDuration:0.25delay:0usingSpringWithDamping:0.8initialSpringVelocity:1options:UIViewAnimationOptionCurveLinearanimations:^{
self.alterV.transform = CGAffineTransformMakeScale(1.0,1.0);
} completion:^(BOOL finished) {
}];
}
-(void)callPhone:(UIButton*)button{
if (button.tag==99) {
if (self.resultIndex) {
self.resultIndex(button.tag);
}
}
[selfremoveFromSuperview];
}
- 关于ios自定义弹框
- 关于iOS自定义字体
- iOS中关于自定义Tabbar
- 关于 iOS自定义转场动画
- 自定义IOS系统弹框
- <iOS>关于自定义description的一点用法
- iOS关于启动页自定义特殊处理
- iOS中关于自定义模型的存储
- 关于IOS自定义推送消息铃声
- iOS 关于MBProgressHUD的使用 自定义动画
- 关于iOS UIAlertController自定义的那些事儿
- 关于iOS NSOperation 自定义的那些事儿
- 关于iOS tableview自定义区头
- ios关于故事版的tabbar自定义
- iOS 自定义弹窗
- 自定义iOS搜索框
- IOS 自定义复选框
- iOS 自定义提示框
- Oracle like 优化
- AS template
- Android百度地图定位sdk 类方法参数、定位原理详细介绍
- cordova camera插件——摄像头插件的使用及上传图片
- 八爪鱼采集:赶集网电话号码采集图文教程
- 关于ios自定义弹框
- UOJ 2017NOI Round #2 T1:UOJ拯救计划(排列组合)
- Android 布局文件中的values-v11,values-v14,values-v19代表的含义
- js判断客户是用pc,android,还是ios,登录实现
- TP5 提示Namespace declaration statement has to be the very first statement in the script
- yyyyMMddHHmmss转变为日期格式
- Pandas学习笔记之重复数据统计
- tee driver 对共享内存的管理
- Nginx 单机百万QPS环境搭建