自定义控件,实现部分

 - (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的更多相关文章

  1. IOS学习笔记25—HTTP操作之ASIHTTPRequest

    IOS学习笔记25—HTTP操作之ASIHTTPRequest 分类: iOS2012-08-12 10:04 7734人阅读 评论(3) 收藏 举报 iosios5网络wrapper框架新浪微博 A ...

  2. iOS学习笔记之ARC内存管理

    iOS学习笔记之ARC内存管理 写在前面 ARC(Automatic Reference Counting),自动引用计数,是iOS中采用的一种内存管理方式. 指针变量与对象所有权 指针变量暗含了对其 ...

  3. IOS学习笔记02---语言发展概述,计算机语言简介.

    IOS学习笔记02---语言发展概述,计算机语言简介. ------------------------------------------------------------------------ ...

  4. IOS学习笔记48--一些常见的IOS知识点+面试题

      IOS学习笔记48--一些常见的IOS知识点+面试题   1.堆和栈什么区别? 答:管理方式:对于栈来讲,是由编译器自动管理,无需我们手工控制:对于堆来说,释放工作由程序员控制,容易产生memor ...

  5. iOS学习笔记31-从图册获取图片和视频

    一.从图册中获取本地图片和视频 从图册中获取文件,我们使用的是UIImagePickerController,这个类我们在之前的摄像头中使用过,这里是链接:iOS学习笔记27-摄像头,这里我们使用的是 ...

  6. iOS学习笔记13-网络(二)NSURLSession

    在2013年WWDC上苹果揭开了NSURLSession的面纱,将它作为NSURLConnection的继任者.现在使用最广泛的第三方网络框架:AFNetworking.SDWebImage等等都使用 ...

  7. iOS学习笔记——AutoLayout的约束

    iOS学习笔记——AutoLayout约束 之前在开发iOS app时一直以为苹果的布局是绝对布局,在IB中拖拉控件运行或者直接使用代码去调整控件都会发上一些不尽人意的结果,后来发现iOS在引入了Au ...

  8. IOS学习笔记之关键词@dynamic

    IOS学习笔记之关键词@dynamic @dynamic这个关键词,通常是用不到的. 它与@synthesize的区别在于: 使用@synthesize编译器会确实的产生getter和setter方法 ...

  9. iOS学习笔记-精华整理

    iOS学习笔记总结整理 一.内存管理情况 1- autorelease,当用户的代码在持续运行时,自动释放池是不会被销毁的,这段时间内用户可以安全地使用自动释放的对象.当用户的代码运行告一段 落,开始 ...

随机推荐

  1. 【技术】JavaSE环境下JPA实体类自动注册

    在没有容器支持的环境下,JPA的实体类(Entity)一般要在persistence.xml中逐个注册,类似下面这样: <?xml version="1.0" encodin ...

  2. matlab画图形函数 semilogx

    matlab画图形函数 semilogx loglog 主要是学习semilogx函数,其中常用的是semilogy函数,即后标为x的是在x轴取对数,为y的是y轴坐标取对数.loglog是x y轴都取 ...

  3. jQuery问题集锦

    [1]阻止提交表单 方法1: $(function () { $("input[type=submit]").click(function (event) { //如果不满足表单提 ...

  4. scrollTop和offsetTop的区别,scrollTopLeft和offsetLeft的区别

    scrollTop和offsetTop的区别:scrollTop是指某个可滚动区块向下滚动的距离,比如向下滚动了10个像素,那么这个元素的scrollTop属性值就是10,这个属性的值是可读写的,且不 ...

  5. 安装Ubuntu之后

    一.Ubuntu is better than fedora I used to use Utuntu 14.04,it's a LTS(long term support) edition. I d ...

  6. 【JavaEE企业应用实战学习记录】logFilter

    package sanglp.servlet; import javax.servlet.*; import javax.servlet.annotation.WebFilter; import ja ...

  7. C++之父Bjarne Stroustrup提供的关于异常处理的建议

    节选自<The C++ Programming Language> ——C++之父Bjarne Stroustrup          1. Don’t use exceptions wh ...

  8. difference between append and appendTo

    if you need append some string to element and need set some attribute on these string at the same ti ...

  9. springMvc全局异常处理

    本文中只测试了:实现Spring的异常处理接口HandlerExceptionResolver 自定义自己的异常处理器 对已有代码没有入侵性等优点,同时,在异常处理时能获取导致出现异常的对象,有利于提 ...

  10. pdo简单操作

    PDO(PHP Data Object) 是PHP 5新出来的东西,在PHP 6都要出来的时候,PHP 6只默认使用PDO来处理数据库,将把所有的数据库扩展移到了PECL,那么默认就是没有了我们喜爱的 ...