【代码笔记】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 ...
随机推荐
- windows 系统安装git的方法
windows 系统安装git的方法 msysgit是Windows版的Git,从https://git-for-windows.github.io下载 安装默认步骤,一步步安装即可 安装完成后,在开 ...
- 线程中的同步辅助类Semaphore
同步辅助类 线程池 并发集合类 都是在线程同步的基础上增加了一些同步的东西,在线程同步的基础上更好的实现线程同步.实现的效率更高,更方便而已. 多线程并不是很难 需要你把代码写出来...然后分析运 ...
- echarts初探
最近经常看到echarts,觉得很有意思,并且这个库是百度开发的,目前来说使用的也很广泛,包括百度.阿里.腾讯.网易.小米.新浪.华为.联想.美团等一大批一线互联网公司在使用,且github上的sta ...
- 10分钟打造强大的gvim
感谢Ruchee的共享精神,让我等vim新手省去了配置vim的麻烦(教程地址:配置文件使用指南). 只需要简单的6个步骤,就可以配置完成一个强大的gvim神器,下图是我的最终配置效果图. (另外,我的 ...
- Zookeeper--0200--安装与集群搭建、常用命令、客户端工具
看这里,http://www.cnblogs.com/lihaoyang/p/8358153.html 1,先使用可视化客户端软件 ZooInspector 连接上集群中的一个节点,看下zk的结构: ...
- 使用控制台程序搭建OAuth授权服务器
参考地址:ASP.NET Web Api: Understanding OWIN/Katana Authentication/Authorization Part I: Concepts 先上一张OA ...
- 帝国CMS-后台使用
后台管理----- 网址wxtoupiao111.com 后台http://wxtoupiao111.com/e/admin/账号密码认证码admin 数据库 账号root 密码空http://wx ...
- Android_OnLowMemory和OnTrimMemory
Android OnLowMemory和OnTrimMemory OnLowMemoryOnLowMemory是Android提供的API,在系统内存不足,所有后台程序(优先级为background的 ...
- Element ui tree结合Vue使用遇到的一些问题(一)
下图是一个后台管理系统,展示的是角色列表 当我点击编辑的时候,弹出一个模态框,如下图 功能需求:点击编辑按钮,弹出模态框,选择权限那块,默认选中当前角色拥有的权限. 问题:第一次点击编辑按钮时,不会选 ...
- 浅尝Vue.js组件(一)
本篇目录: 组件名 组件注册 全局注册 基础组件的自动化全局注册 局部注册 在模块系统中局部注册 Prop 单向数据流 Prop验证 类型检查 非Prop特性 替换/合并已有的特性 禁用特性继承 自定 ...