一,效果图。

二,代码。

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
UIView *alertView;
}
@end

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. //背景色
self.view.backgroundColor=[UIColor redColor];
//增加背景图
[self addBackGroundView]; }
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
alertView.hidden=NO;
}
#pragma -mark -functions
-(void)addBackGroundView
{
//提示背景
alertView = [[UIView alloc]initWithFrame:CGRectMake(70, 300,220, 90)];
alertView.layer.borderColor = [UIColor lightGrayColor].CGColor;
alertView.layer.borderWidth=0.3;
alertView.layer.cornerRadius = 5;
alertView.layer.masksToBounds = YES;
alertView.backgroundColor = [UIColor whiteColor];
alertView.hidden=YES;
[self.view addSubview:alertView]; //请输入MAC地址
UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(0,0, alertView.frame.size.width, 45)];
titleLabel.text=@"请输入MAC地址";
titleLabel.font=[UIFont systemFontOfSize:14];
titleLabel.textAlignment=NSTextAlignmentCenter;
titleLabel.backgroundColor=[UIColor clearColor];
[alertView addSubview:titleLabel]; //线
UIView * separateLine = [[UIView alloc]initWithFrame:CGRectMake(0, titleLabel.frame.size.height+titleLabel.frame.origin.y, alertView.frame.size.width, 0.5)];
separateLine.backgroundColor=[UIColor colorWithRed:218/255.0 green:218/255.0 blue:218/255.0 alpha:1.0];
[alertView addSubview:separateLine]; //知道了
UILabel *clickLabel=[[UILabel alloc]initWithFrame:CGRectMake(0,separateLine.frame.origin.y+separateLine.frame.size.height, alertView.frame.size.width, alertView.frame.size.height-separateLine.frame.size.height-separateLine.frame.origin.y)];
clickLabel.text=@"知道了";
clickLabel.font=[UIFont systemFontOfSize:14];
clickLabel.textAlignment=NSTextAlignmentCenter;
clickLabel.backgroundColor=[UIColor clearColor];
clickLabel.textColor=[UIColor blueColor];
clickLabel.userInteractionEnabled=YES;
[alertView addSubview:clickLabel]; //知道点击按钮
UIButton *alerButton=[UIButton buttonWithType:UIButtonTypeCustom];
alerButton.frame=CGRectMake(0,separateLine.frame.origin.y+separateLine.frame.size.height, alertView.frame.size.width, alertView.frame.size.height-separateLine.frame.size.height-separateLine.frame.origin.y);
alerButton.backgroundColor=[UIColor clearColor];
[alerButton addTarget:self action:@selector(doClickButton:) forControlEvents:UIControlEventTouchUpInside];
alerButton.titleLabel.font=[UIFont systemFontOfSize:12];
[alertView addSubview:alerButton]; }
#pragma -mark -doClickActions
//知道点击按钮
-(void)doClickButton:(UIButton *)btn
{
NSLog(@"--doClickLabel---");
alertView.hidden=YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

【代码笔记】iOS-自定义alertView的更多相关文章

  1. IOS自定义alertview

    在家闲来无事,于是就看起来ios绘图的那块,写点什么好呢? 鼓捣了一会,总算写出了一个小东西 这个是写完以后的效果 这里我实现了三种款式的alertview 分别是成功,错误和警告,剩下的呢有空继续添 ...

  2. iOS自定义AlertView 与 ActionSheet 遮罩提示+弹出动画

    产品大人总是能够想到很多让人欣慰的点子,基本所有能提示的地方都要很多文案啊图片之类 由此封装了一个半透明黑色遮罩的alert类(假装有图.jpg) 代码略糙,just share (逃 下载链接

  3. iOS 第三方自定义Alertview项目MBProcessHud中的重要代码分析

    做ios,弹出一个自定义的alertview挺常见的.ios7以前,我们可以对系统的UIAlertView进行一点操作,实现一点简单的定制,但是ios7不再允许我们这样做了.因此,我们需要自己创建一个 ...

  4. iOS 自定义导航栏笔记

    一.UINavigationBar的结构 导航栏几乎是每个页面都会碰到的问题,一般两种处理方式:1.隐藏掉不显示 2.自定义 1. 添加导航栏 TestViewController * mainVC ...

  5. 【iOS自定义键盘及键盘切换】详解

    [iOS自定义键盘]详解 实现效果展示: 一.实现的协议方法代码 #import <UIKit/UIKit.h> //创建自定义键盘协议 @protocol XFG_KeyBoardDel ...

  6. 笔记-iOS 视图控制器转场详解(上)

    这是一篇长文,详细讲解了视图控制器转场的方方面面,配有详细的示意图和代码,为了使得文章在微信公众号中易于阅读,seedante 辛苦将大量长篇代码用截图的方式呈现,另外作者也在 Github 上附上了 ...

  7. iOS自定义的UISwitch按钮

    UISwitch开关控件 开关代替了点选框.开关是到目前为止用起来最简单的控件,不过仍然可以作一定程度的定制化. 一.创建 UISwitch* mySwitch = [[ UISwitchalloc] ...

  8. IOS开发笔记 IOS如何访问通讯录

    IOS开发笔记  IOS如何访问通讯录 其实我是反对这类的需求,你说你读我的隐私,我肯定不愿意的. 幸好ios6.0 以后给了个权限控制.当打开app的时候你可以选择拒绝. 实现方法: [plain] ...

  9. Hadoop学习笔记—5.自定义类型处理手机上网日志

    转载自http://www.cnblogs.com/edisonchou/p/4288737.html Hadoop学习笔记—5.自定义类型处理手机上网日志 一.测试数据:手机上网日志 1.1 关于这 ...

  10. OpenGL ES: iOS 自定义 UIView 响应屏幕旋转

    iOS下使用OpenGL 如果使用GLKit View 那么不用担心屏幕旋转的问题,说明如下: If you change the size, scale factor, or drawable pr ...

随机推荐

  1. CentOS7安装MYSQL。

    参考这个文章(网页已存到本地):http://www.cnblogs.com/starof/p/4680083.html 安装完成后,本地登录MYSQL没有问题. 现在主要是在windows下用ora ...

  2. D13——C语言基础学PYTHON

    C语言基础学习PYTHON——基础学习D13 20180918内容纲要: 堡垒机运维开发 1.堡垒机的介绍 2.堡垒机的架构 3.小结 4.堡垒机的功能实现需求 1 堡垒机的介绍 百度百科 随着信息安 ...

  3. Python小白学习之路(二十五)—【装饰器的应用】

    通过一个任务来加深对装饰器的理解和应用 回顾:装饰器的框架 def timmer(func): def wrapper(): func() return wrapper 任务:给以下正在运行的程序加一 ...

  4. 谈一谈对MySQL InnoDB的认识及数据库事物处理的隔离级别

    介绍: InnoDB引擎是MySQL数据库的一个重要的存储引擎,和其他存储引擎相比,InnoDB引擎的优点是支持兼容ACID的事务(类似于PostgreSQL),以及参数完整性(有外键)等.现在Inn ...

  5. hao643.com劫持(修改快捷方式跳转至hao123.com)

    >症状:所有浏览器快捷方式,都被加上尾巴,例如IE的:"C:\Program Files\Internet Explorer\iexplore.exe" http://hao ...

  6. [Java初探外篇]__关于时间复杂度与空间复杂度

    前言 我们在前面的排序算法的学习中了解到了,排序算法的分类,效率的比较所使用到的判断标准,就包括时间复杂度和空间复杂度,当时因为这两个定义还是比较难以理解的,所以决定单独开一篇文章,记录一下学习的过程 ...

  7. mycat中间件--schema.xml配置文件详解

    schema.xml管理着MyCat的逻辑库.表.分片规则.DataNode以及DataSource.弄懂这些配置,是正确使用MyCat的前提. <?xml version="1.0& ...

  8. ActiveMQ——activemq的使用java代码实例(精选)

    ActiveMQ 在java中的使用,通过单例模式.工厂实现 Jms规范里的两种message传输方式Topic和Queue,两者的对比如下表():   Topic Queue 概要 Publish  ...

  9. 【PyTorch深度学习60分钟快速入门 】Part0:系列介绍

      说明:本系列教程翻译自PyTorch官方教程<Deep Learning with PyTorch: A 60 Minute Blitz>,基于PyTorch 0.3.0.post4 ...

  10. k8s使用nfs动态存储

    1.Kubernetes集群管理员通过提供不同的存储类,可以满足用户不同的服务质量级别.备份策略和任意策略要求的存储需求.动态存储卷供应使用StorageClass进行实现,其允许存储卷按需被创建.如 ...