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,当用户的代码在持续运行时,自动释放池是不会被销毁的,这段时间内用户可以安全地使用自动释放的对象.当用户的代码运行告一段 落,开始 ...
随机推荐
- js的数组
转载:http://blog.163.com/sammer_rui/blog/static/846200442010717900634/ https://developer.mozilla.org/z ...
- Java 增强型的for循环 for each
Java 增强型的for循环 for each For-Each循环 For-Each循环也叫增强型的for循环,或者叫foreach循环. For-Each循环是JDK5.0的新特性(其他新特性比如 ...
- 【Spring】构建Springboot项目 实现restful风格接口
项目代码如下: package hello; import org.springframework.boot.SpringApplication; import org.springframework ...
- 【JavaEE企业应用实战学习记录】struts2登录
<%-- login.jsp Created by IntelliJ IDEA. User: Administrator Date: 2016/10/6 Time: 16:26 To chang ...
- 通过android 客户端上传图片到服务器
昨天,(在我的上一篇博客中)写了通过浏览器上传图片到服务器(php),今天将这个功能付诸实践.(还完善了服务端的代码) 不试不知道,原来通过android 向服务端发送图片还真是挺麻烦的一件事. 上传 ...
- python基础_字典_列表_元组考试_day4
1.请用代码实现:利用下划线将列表的每一个元素拼接成字符串,li=['alex','eric','rain'] li=['alex','eric','rain'] v="_".jo ...
- 使用delegate实现简单的查询功能
protected void imgbtnSearch_Click(object sender, System.Web.UI.ImageClickEventArgs e) { string keyWo ...
- 屠龙之路_狭路相逢勇者胜_EighthDay
屠龙天团的少年们追着Alpha恶龙沿路留下的粪便,一路狂奔追到了福州大学生活区三十号楼4层活动室,空气中弥漫着恶龙的臭味!屠龙少年对恶龙的隐身遁迹之术心知肚明,于是点头示意,四下散开.各自拿出了电脑, ...
- Android无线调试及手机设备与PC同屏工具——Chrome插件Vysor
我们平时用手机调试时,经常是手不离机,以前可以下载个jar包能把手机屏映射到电脑桌面,但是运行比较卡,后来就放弃了,再之,手机接数据线有时也不太方便 ,pc与手机(连wifi)如处同一网段,就可以通过 ...
- git 创建别名
git config --global alias.shortname command 例子如下 git config --global alias.psm 'push origin master' ...