IOS 学习笔记之UI
自定义控件,实现部分
- (id)initWithFrame:(CGRect)frame descriptionText:(NSArray *)inText/*需要输入两个字符串*/
{
self = [super init];//通过父类调用init初始化方法,产生一个对象,此处的self就是类的对象
//判断是否初始化成功,未初始化之前,self = nil
if (self)
{
UILabel *myLable = [[UILabel alloc] initWithFrame:CGRectMake(frame.origin.x, frame.origin.y, frame.size.width/, frame.size.height)];
myLable.text = inText[];
myLable.textColor = [UIColor blueColor];//字体颜色
[self addSubview:myLable];
UITextField *myText = [[UITextField alloc] initWithFrame:CGRectMake(frame.size.width/, frame.origin.y, frame.size.width/*, frame.size.height)];
myText.placeholder = inText[];
myText.borderStyle = UITextBorderStyleRoundedRect;//边框样式(圆角)
[self addSubview:myText];
}
return self;//self包括(super init、addSubview:myLablea、ddSubview:myText)
}
调用部分
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//设置window(注意:该处必须设置)
self.window = [[UIWindow alloc] init];
self.window.frame = [[UIScreen mainScreen] bounds];//指定window大小跟屏幕大下一致
self.window.backgroundColor = [UIColor grayColor];//UIWindow中的方法,背景颜色
MyUIView *myUIViewInstance1 = [[MyUIView alloc] initWithFrame:CGRectMake(, , , ) descriptionText:@[@"用户名:",@"请输入手机号或邮箱"]];
MyUIView *myUIViewInstance2 = [[MyUIView alloc] initWithFrame:CGRectMake(, , , ) descriptionText:@[@"密码:",@"必须同时包含字符和数字"]];
[self.window addSubview:myUIViewInstance1];
[self.window addSubview:myUIViewInstance2];
[self.window makeKeyAndVisible];//显示(使其可见)
return YES;
}
基础部分
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//程序入口
//设置window
self.window = [[UIWindow alloc] init];
// self.window.frame = CGRectMake(0, 0, 100, 100);//指定窗口位置和大小
self.window.frame = [[UIScreen mainScreen] bounds];//指定window大小跟屏幕大下一致
self.window.backgroundColor = [UIColor grayColor];//UIWindow中的方法,背景颜色
//设置view
//创建view1
UIView *view1 = [[UIView alloc] init];
// UIView *view1 = [[UIView alloc] initWithCoder:(NSCoder *)];
// UIView *view1 = [[UIView alloc] initWithFrame:(CGRect)];
view1.frame = CGRectMake(, , , );//设置位置大小
view1.backgroundColor = [UIColor orangeColor];//背景颜色
//将view1加入window
// [self.window addSubview:view1];
NSLog(@"---%@",self.window.subviews);
//集合会自动对它的元素做retain操作
/*
hidden:隐藏
alpha:透明度
supwiew:父视图
tag:标记,便于索引(比如view的索引)
eg:
view1.tag = 10;
UIView *v = [self.window viewWithTag:10];//索引view1
*/
//UIlable
UILabel *myLable = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
myLable.backgroundColor = [UIColor whiteColor];
[self.window addSubview:myLable];
//UItext
UITextField *myText = [[UITextField alloc] initWithFrame:CGRectMake(, , , )];
myText.borderStyle = UITextBorderStyleRoundedRect;//边框样式(圆角)
myText.placeholder = @"手机号/邮箱";//占位符
// [view1 addSubview:myText];
[self.window addSubview:myText];
//UIButton+点击事件
// UIButton *myButton = [[UIButton alloc] initWithFrame:CGRectMake(120, 150, 80, 30)];
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeSystem];//标准系统按钮,圆角形
myButton.frame = CGRectMake(, , , );
myButton.backgroundColor = [UIColor orangeColor];//橙黄色
[myButton setTitle:@"登陆" forState:UIControlStateNormal];//设置标题和状态(正常)
[myButton addTarget:self/*对象*/ action:@selector(prin/*处理程序*/) forControlEvents:UIControlEventTouchUpInside/*事件*/];//松手检测
[self.window addSubview:myButton];
//UIAlertView
// UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请妥善保管你的密码" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
// [myAlert show];
[self.window makeKeyAndVisible];//显示(使其可见)
return YES;
}
- (void)prin
{
// NSLog(@"登陆成功");
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请妥善保管你的密码" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[myAlert show];//显示
}
IOS 学习笔记之UI的更多相关文章
- IOS学习笔记25—HTTP操作之ASIHTTPRequest
IOS学习笔记25—HTTP操作之ASIHTTPRequest 分类: iOS2012-08-12 10:04 7734人阅读 评论(3) 收藏 举报 iosios5网络wrapper框架新浪微博 A ...
- iOS学习笔记之ARC内存管理
iOS学习笔记之ARC内存管理 写在前面 ARC(Automatic Reference Counting),自动引用计数,是iOS中采用的一种内存管理方式. 指针变量与对象所有权 指针变量暗含了对其 ...
- IOS学习笔记02---语言发展概述,计算机语言简介.
IOS学习笔记02---语言发展概述,计算机语言简介. ------------------------------------------------------------------------ ...
- IOS学习笔记48--一些常见的IOS知识点+面试题
IOS学习笔记48--一些常见的IOS知识点+面试题 1.堆和栈什么区别? 答:管理方式:对于栈来讲,是由编译器自动管理,无需我们手工控制:对于堆来说,释放工作由程序员控制,容易产生memor ...
- iOS学习笔记31-从图册获取图片和视频
一.从图册中获取本地图片和视频 从图册中获取文件,我们使用的是UIImagePickerController,这个类我们在之前的摄像头中使用过,这里是链接:iOS学习笔记27-摄像头,这里我们使用的是 ...
- iOS学习笔记13-网络(二)NSURLSession
在2013年WWDC上苹果揭开了NSURLSession的面纱,将它作为NSURLConnection的继任者.现在使用最广泛的第三方网络框架:AFNetworking.SDWebImage等等都使用 ...
- iOS学习笔记——AutoLayout的约束
iOS学习笔记——AutoLayout约束 之前在开发iOS app时一直以为苹果的布局是绝对布局,在IB中拖拉控件运行或者直接使用代码去调整控件都会发上一些不尽人意的结果,后来发现iOS在引入了Au ...
- IOS学习笔记之关键词@dynamic
IOS学习笔记之关键词@dynamic @dynamic这个关键词,通常是用不到的. 它与@synthesize的区别在于: 使用@synthesize编译器会确实的产生getter和setter方法 ...
- iOS学习笔记-精华整理
iOS学习笔记总结整理 一.内存管理情况 1- autorelease,当用户的代码在持续运行时,自动释放池是不会被销毁的,这段时间内用户可以安全地使用自动释放的对象.当用户的代码运行告一段 落,开始 ...
随机推荐
- VS代码管理插件AnkhSvn
下载AnKHSvn软件,启动VS,源代码管理工具选择AnKHSvn 在视图-〉其它窗口-〉Pending Change->提交变化的更改
- C# 退出应用程序办法
Application.Exit();//好像只在主线程可以起作用,而且当有线程,或是阻塞方法的情况下,很容易失灵 this.Close();//只是关闭当前窗体. Application.E ...
- 《TCP/IP详解卷1:协议》第1章 概述-读书笔记
章节回顾: <TCP/IP详解卷1:协议>第1章 概述-读书笔记 <TCP/IP详解卷1:协议>第2章 链路层-读书笔记 <TCP/IP详解卷1:协议>第3章 IP ...
- 11-cp 命令总结
- 深入理解Java:注解(Annotation)自定义注解入门
转载:http://www.cnblogs.com/peida/archive/2013/04/24/3036689.html 元注解: 元注解的作用就是负责注解其他注解.Java5.0定义了4个标准 ...
- MySQL数据库my.cnf性能参数如何调优
提供一个MySQL 5.6版本适合在1GB内存VPS上的my.cnf配置文件.配置文件可以到这里下载:: 下载my.cnf [client] port = 3306 socket = /tmp/mys ...
- zabbix_server的自动发现,实现批量添加主机,并链接到模板
一.需求 zabbix 服务器可以手动加入zabbix-agent客户端,对于少量的机器,这没有什么.但到了线上,我们有大量的服务器需要监控时,如果再一个个的手动加的话,工作量势必会增加很多.这时,z ...
- 函数也是对象,本片介绍函数的属性、方法、Function()狗仔函数。
1.arguments.length表示实参的个数. 2.arguments.callee.length表示形参个数. function test(a,b,c,d,e,f){ alert(argume ...
- ActiveMQ(八)_多集群的负载均衡
图一 图一说明: 1.集群一包含3个队列:A ...
- java.net.URL请求远程文件下载
1:浏览器请求下载 public void listStockcodeUplaod(HttpServletRequest req, HttpServletResponse res) throws Ex ...