【代码笔记】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 ...
随机推荐
- iOS开发-仿微信图片分享界面实现
分享功能目前几乎已成为很多app的标配了,其中微信,微博等app的图片分享界面设计的很棒,不仅能够展示缩略图,还可以预览删除.最近我在做一款社交分享app,其中就要实现图文分享功能,于是试着自行实现仿 ...
- 《Python编程从入门到实践》--- 学习过程笔记(3)列表
一.用[](方括号)表示列表,用,(逗号)分隔其中的元素. >>> name=['limei', 'hanmeimei', 'xiaoming'] >>> prin ...
- POJ 2608
#include<iostream> #include<stdio.h> #include<string> #include<set> using na ...
- ASP.NET Core 1.0 中 EntityFramework 与 PostgreSQL 的使用
https://docs.efproject.net/en/latest/providers/npgsql/index.html 前面在CentOS6.7环境下配置好了PostgreSQL, 就顺便试 ...
- Nginx限制访问次数和并发数
Nginx限制访问速率和最大并发连接数模块--limit (防止DDOS攻击) http: ##zone=one或allips 表示设置名为"one"或"allips&q ...
- struts和hibernate整合
程序示例: 1.引入jar包 2.实体对象 Dept.java package com.gqx.entity; import java.util.HashSet; import java.util.S ...
- Java中的简单工厂模式(转)
Java中的简单工厂模式 举两个例子以快速明白Java中的简单工厂模式: 女娲抟土造人话说:“天地开辟,未有人民,女娲抟土为人.”女娲需要用土造出一个个的人,但在女娲造出人之前,人的概念只存在于女娲的 ...
- Edge和Chrome浏览器滚屏截取网页
1.Edge打开需要截图的页面,选择下面的功能: 在页面按下左键选中需要截图的区域(不要放开左键,这时可以滚动鼠标滚轮到底部),放开左键后就完成截图,直接可以粘贴到QQ或其他地方. 2,Chrome截 ...
- ansible 角色登陆
用ansible 来管理远程的主机,最大的好处是方便,ansible不用在远程的主机上安装ansible的客户端,ansible只要能通过ssh连接上远程主机就 能对它进行管理.也就是说ansible ...
- mysql cmd 启动服务
1.确定你的mysql 是否能正常工作登录数据库cmd--“命令提示字符”窗口录入,录入cd C:\mysql\bin 并按下回车键,将目录切换为 cd C:\mysql\bin再键入命令mysql ...