一,效果图。

二,代码。

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. HTTP的请求报文与响应报文

    报文: 简单来说,报文就是也就是HTTP报文,作用是在各个系统之间进行和响应时用来交换与传输的数据单元,即站点一次性要发送的数据块,这些数据块以一些文本形式的元信息开头,这些信息描述了报文的内容及含义 ...

  2. _tkinter.TclError: image "pyimage1" doesn't exist 解决办法

    _tkinter.TclError: image "pyimage1" doesn't exist 解决办法 1 def logout(self): 2 login.LoginWi ...

  3. 解决Navicat Premium终端操作mysql ONLY_FULL_GROUP_BY错误

    解决navicate终端操作mysql ONLY_FULL_GROUP_BY错误     问题描述: [Err] 1055 - Expression #1 of SELECT list is not ...

  4. Docker 创建 mysql 容器

    docker -v Docker version 18.06.1-ce, build e68fc7a   拉取 docker mysql 最新的镜像 docker pull mysql   Using ...

  5. 【转载】InstallShield 生成安装日志

    msiexec.exe /p "C:\Documents and Settings\qa\Desktop\8.3 Patch.msp" /l*v c:\log85gold.log ...

  6. (转) JVM Crash with SIGSEGV - problematic frame - libzip.so

    原文:https://stackoverflow.com/questions/38057362/jvm-crash-with-sigsegv-problematic-frame-libzip-so h ...

  7. 解决Redisson出现Failed to instantiate [org.redisson.api.RedissonClient]: Factory method 'create' threw exception; nested exception is java.lang.ArrayIndexOutOfBoundsException: 0的问题

    一.背景 最近项目中使用了redisson的哨兵模式来作为redis操作的客户端,然后一个意外出现了,启动报:Failed to instantiate [org.redisson.api.Redis ...

  8. Vue笔记:使用node开发vue入门实例

    安装NPM 首先在命令终端输入 npm -v 检测是否安装 npm.如果没有,按照下面教程进行安装. 下载地址: nodejs中文网 到官网下载自己系统对应的版本,这里我们下载Windows系统的64 ...

  9. springMVC上传文件简单案例

    html <form name="Form2" action="/SpringMVC006/fileUpload2" method="post& ...

  10. Python3 中使用sys.argv详解

    #/usr/bin/env python #coding:utf-8 import sys # print(sys.argv[1]) def readFile(filename): "&qu ...