【代码笔记】iOS-自定义alertView
一,效果图。
二,代码。
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的更多相关文章
- IOS自定义alertview
在家闲来无事,于是就看起来ios绘图的那块,写点什么好呢? 鼓捣了一会,总算写出了一个小东西 这个是写完以后的效果 这里我实现了三种款式的alertview 分别是成功,错误和警告,剩下的呢有空继续添 ...
- iOS自定义AlertView 与 ActionSheet 遮罩提示+弹出动画
产品大人总是能够想到很多让人欣慰的点子,基本所有能提示的地方都要很多文案啊图片之类 由此封装了一个半透明黑色遮罩的alert类(假装有图.jpg) 代码略糙,just share (逃 下载链接
- iOS 第三方自定义Alertview项目MBProcessHud中的重要代码分析
做ios,弹出一个自定义的alertview挺常见的.ios7以前,我们可以对系统的UIAlertView进行一点操作,实现一点简单的定制,但是ios7不再允许我们这样做了.因此,我们需要自己创建一个 ...
- iOS 自定义导航栏笔记
一.UINavigationBar的结构 导航栏几乎是每个页面都会碰到的问题,一般两种处理方式:1.隐藏掉不显示 2.自定义 1. 添加导航栏 TestViewController * mainVC ...
- 【iOS自定义键盘及键盘切换】详解
[iOS自定义键盘]详解 实现效果展示: 一.实现的协议方法代码 #import <UIKit/UIKit.h> //创建自定义键盘协议 @protocol XFG_KeyBoardDel ...
- 笔记-iOS 视图控制器转场详解(上)
这是一篇长文,详细讲解了视图控制器转场的方方面面,配有详细的示意图和代码,为了使得文章在微信公众号中易于阅读,seedante 辛苦将大量长篇代码用截图的方式呈现,另外作者也在 Github 上附上了 ...
- iOS自定义的UISwitch按钮
UISwitch开关控件 开关代替了点选框.开关是到目前为止用起来最简单的控件,不过仍然可以作一定程度的定制化. 一.创建 UISwitch* mySwitch = [[ UISwitchalloc] ...
- IOS开发笔记 IOS如何访问通讯录
IOS开发笔记 IOS如何访问通讯录 其实我是反对这类的需求,你说你读我的隐私,我肯定不愿意的. 幸好ios6.0 以后给了个权限控制.当打开app的时候你可以选择拒绝. 实现方法: [plain] ...
- Hadoop学习笔记—5.自定义类型处理手机上网日志
转载自http://www.cnblogs.com/edisonchou/p/4288737.html Hadoop学习笔记—5.自定义类型处理手机上网日志 一.测试数据:手机上网日志 1.1 关于这 ...
- OpenGL ES: iOS 自定义 UIView 响应屏幕旋转
iOS下使用OpenGL 如果使用GLKit View 那么不用担心屏幕旋转的问题,说明如下: If you change the size, scale factor, or drawable pr ...
随机推荐
- MyBatis全局配置文件标签详解
一.全局配置文件结构 configuration 配置 properties 属性:可以加载properties配置文件的信息 settings 设置:可以设置mybatis的全局属性 typeAli ...
- .gitignore总结
git进行管理时,.gitignore是必不可少的,可以指定不需要提交到仓库的资源.最好在git init之后就创建 .gitignore文件,这是个好习惯,常用的配置及说明如下:
- jq 复习帖子 常用操作
1绝对定位(abs)与相对定位(relative) 区别是相对定位参照自己的位置进行移动(当然需要设置top left这些生效)并且原来的位置保留着 偏移后会把其它的层遮罩住 绝对定位就 ...
- opencv2.4.13.7的resize函数使用(c++)
先来看一下resize函数的原型,如下. C++: void resize(InputArray src, OutputArray dst, Size dsize, double fx=0, doub ...
- 浅析XSS与CSRF
浅析XSS与CSRF 在 Web 安全方面,XSS 与 CSRF 可以说是老生常谈了. XSS XSS,即 cross site script,跨站脚本攻击,缩写原本为 CSS,但为了和层叠样式表(C ...
- POJ 2681
#include<iostream> #include<stdio.h> #include<string> #include<algorithm> #d ...
- 03-03 java 顺序语句结构,选择结构if语句
顺序结构: /* 流程控制语句:可以控制程序的执行流程. 分类: 顺序结构 选择结构 循环结构 顺序结构: 从上往下,依次执行. */ class ShunXuJieGouDemo { public ...
- Quartz.NET基础知识概述
Quartz.NET是什么 由于我现在使用的Quartz.NET2.2版本,相对2.x变化不大,主要是相对于1.x更新了很多东西,如下基础知识摘录网络. Quartz.NET是一个开源的作业调度框架, ...
- 公共技术点( View 绘制流程)
转载地址:http://p.codekk.com/blogs/detail/54cfab086c4761e5001b253f 本文为 Android 开源项目源码解析 公共技术点中的 View 绘制流 ...
- zmq 三种模型的python实现
1.Request-Reply模式: 客户端在请求后,服务端必须回响应 server: #!/usr/bin/python #-*-coding:utf-8-*- import time import ...