IOS UI 01 课堂笔记 -label
2015-12-13 15:37
344 查看
//
// RootViewController.m
// UI1_View_Label
//
// Created by TravelRound on 15/11/6.
// Copyright © 2015年 TravelRound. All rights reserved.
//
#import "RootViewController.h"
@interface
RootViewController ()
@end
@implementation RootViewController
- (void)viewDidLoad {
[super
viewDidLoad];
// Do any additional setup after loading the view.
//
代码写在此处
self.view.backgroundColor = [UIColor
purpleColor];
// // 创建画布
// UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 200, 200)];
//
// // 设置背景色
// view1.backgroundColor = [UIColor greenColor];
//
// // 将view1添加到self.view上
// [self.view addSubview:view1];
//
// [view1 release];
//
// UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(80, 100, 200, 200)];
//
// // 设置背景色
// view2.backgroundColor = [UIColor yellowColor];
//
// // 将view1添加到self.view上
// [self.view addSubview:view2];
//
// [view2 release];
//
// UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(10, 30, 100, 100)];
//
// // 设置背景色
// view3.backgroundColor = [UIColor cyanColor];
//
// // 子视图的坐标相对于父视图的坐标系
// [view2 addSubview:view3];
//
// [view3 release];
//
//// self.view.subviews
//// self.view.superview
//
//
// // subviews - nsarray类型 -
子视图数组
// // 通过父视图找到子视图
//// [[self.view.subviews objectAtIndex:1] setBackgroundColor:[UIColor lightGrayColor]];
//// [self.view.subviews objectAtIndex:1].backgroundColor = [UIColor lightGrayColor];
//// UIView *subV = [self.view.subviews objectAtIndex:1];
//// subV.backgroundColor = [UIColor lightGrayColor];
//
// // superview - uiview类型 -
父视图
//// view3.superview.backgroundColor = [UIColor orangeColor];
//
//
// // 视图的操作
// // 自定义色彩,
注意:1, 参数范围0~1; 2,
注意整数相除结果只保留整数部分
//// view3.backgroundColor = [UIColor colorWithRed:155 / 255.0 green:175 /255.0 blue:194 / 255.0 alpha:1.0];
//
// // 透明度
//// view3.alpha = 0.2;
//
// // 标签
// // 注意,
标签值一般设置较大, 因为较小的tag已经被系统占用
//// view3.tag = 10001;
//
//// // frame - 设置坐标及尺寸
//// view3.frame = CGRectMake(100, 100, 20, 20);
////
//// // center - 中心坐标
//// view3.center = CGPointMake(150, 150);
//
// // bounds - 设置坐标及尺寸 -
坐标相对于自身
//// view3.bounds = CGRectMake(10, 10, 200, 200);
//
//// view2.bounds = CGRectMake(10, 0, 200, 200);
//// view2.bounds = CGRectMake(0, 30, 200, 200);
//// view2.bounds = CGRectMake(10, 30, 200, 200);
//
//
// // 视图层级操作
// UIView *view4 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
// view4.backgroundColor = [UIColor blueColor];
// view4.tag = 10002;
// [self.view addSubview:view4];
// [view4 release];
//
//// [self.view insertSubview:view4 aboveSubview:view1];
//// [self.view insertSubview:view4 belowSubview:view1];
//// [self.view insertSubview:view4 atIndex:1];
//
// // 实用方法,
将某一视图移到最前端
//// [self.view bringSubviewToFront:view1];
// // 将某一视图从父视图上移除
//// [view4 removeFromSuperview];
//
// // 隐藏view及子视图 -
默认关闭
//// view2.hidden = NO;
//
// // 计时器
// // 参数1:时间
// // 参数2:可填写方法所在的对象
// // 参数3:定时进入的处理方法
// // 参数4:nil
// // 参数5:是否重复计时
// [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
UILabel *label = [[UILabel
alloc] initWithFrame:CGRectMake(50, 50, 100, 130)];
label.backgroundColor = [UIColor
whiteColor];
//
显示内容
label.text =
@"庆春儿庆春儿庆春儿庆春儿庆春儿庆春儿庆春儿庆春儿庆春儿庆春儿庆春儿庆春儿";
//
文字颜色
label.textColor = [UIColor
blueColor];
//
文字大小
label.font = [UIFont
systemFontOfSize:27.0];
// 加粗并设置文字大小
label.font = [UIFont
boldSystemFontOfSize:27.0];
//
对齐方式
label.textAlignment =
NSTextAlignmentRight;
//
显示行数
//
注意, 要label高度足够
// 当赋值为0时,
代表自动分配行数
label.numberOfLines = 3;
// 断行模式
省略号放在哪
label.lineBreakMode =
NSLineBreakByTruncatingMiddle;
//
阴影颜色
label.shadowColor = [UIColor
yellowColor];
//
阴影偏移量
label.shadowOffset =
CGSizeMake(2, 3);
[self.view
addSubview:label];
[label release];
//
输入框
// UITextField *field = [[UITextField alloc] initWithFrame:CGRectMake(150, 50, 100, 50)];
UITextField *field = [[UITextField
alloc] initWithFrame:CGRectMake(label.frame.origin.x
+ label.frame.size.width + 20, label.frame.origin.y,
100, 50)];
field.backgroundColor = [UIColor
whiteColor];
// text属性可读可写,
当读的时候可获取用户输入内容
// field.text = @"请输入";
field.placeholder =
@"请输入";
//
清除按钮
field.clearButtonMode =
UITextFieldViewModeAlways;
//
密文输入
field.secureTextEntry =
YES;
//
键盘模式
field.keyboardType =
UIKeyboardTypeDefault;
//
是否允许输入 - 默认允许
// field.enabled = NO;
// 允许开始输入时清除内容
field.clearsOnBeginEditing =
YES;
// return按键的模式
field.returnKeyType =
UIReturnKeyNext;
//
边框样式
field.borderStyle =
UITextBorderStyleRoundedRect;
[self.view
addSubview:field];
[field release];
UIButton *button = [UIButton
buttonWithType:UIButtonTypeCustom];
button.frame =
CGRectMake(200, 200, 50, 50);
button.backgroundColor = [UIColor
brownColor];
// button的核心方法
[button addTarget:self
action:@selector(buttonAction:)
forControlEvents:UIControlEventTouchUpInside];
//
移除button的处理方法
// [button removeTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
//
设置文字
[button setTitle:@"登陆"
forState:UIControlStateNormal];
//
设置文字颜色
[button setTitleColor:[UIColor
blueColor] forState:UIControlStateNormal];
[self.view
addSubview:button];
}
// 点击button触发此方法
- (void)buttonAction:(id)sender
{
// if (sender == button1) {
// <#statements#>
// }
self.view.backgroundColor = [UIColor
colorWithRed:(arc4random() % 256) / 255.0
green:(arc4random() % 256) / 255.0
blue:(arc4random() % 256) / 255.0
alpha:1.0];
}
- (void)timerAction
{
// UIView *view = [self.view viewWithTag:10002];
// view.backgroundColor = [UIColor blackColor];
self.view.backgroundColor = [UIColor
colorWithRed:(arc4random() % 256) / 255.0
green:(arc4random() % 256) / 255.0
blue:(arc4random() % 256) / 255.0
alpha:1.0];
}
- (void)didReceiveMemoryWarning {
[super
didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
// RootViewController.m
// UI1_View_Label
//
// Created by TravelRound on 15/11/6.
// Copyright © 2015年 TravelRound. All rights reserved.
//
#import "RootViewController.h"
@interface
RootViewController ()
@end
@implementation RootViewController
- (void)viewDidLoad {
[super
viewDidLoad];
// Do any additional setup after loading the view.
//
代码写在此处
self.view.backgroundColor = [UIColor
purpleColor];
// // 创建画布
// UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 200, 200)];
//
// // 设置背景色
// view1.backgroundColor = [UIColor greenColor];
//
// // 将view1添加到self.view上
// [self.view addSubview:view1];
//
// [view1 release];
//
// UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(80, 100, 200, 200)];
//
// // 设置背景色
// view2.backgroundColor = [UIColor yellowColor];
//
// // 将view1添加到self.view上
// [self.view addSubview:view2];
//
// [view2 release];
//
// UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(10, 30, 100, 100)];
//
// // 设置背景色
// view3.backgroundColor = [UIColor cyanColor];
//
// // 子视图的坐标相对于父视图的坐标系
// [view2 addSubview:view3];
//
// [view3 release];
//
//// self.view.subviews
//// self.view.superview
//
//
// // subviews - nsarray类型 -
子视图数组
// // 通过父视图找到子视图
//// [[self.view.subviews objectAtIndex:1] setBackgroundColor:[UIColor lightGrayColor]];
//// [self.view.subviews objectAtIndex:1].backgroundColor = [UIColor lightGrayColor];
//// UIView *subV = [self.view.subviews objectAtIndex:1];
//// subV.backgroundColor = [UIColor lightGrayColor];
//
// // superview - uiview类型 -
父视图
//// view3.superview.backgroundColor = [UIColor orangeColor];
//
//
// // 视图的操作
// // 自定义色彩,
注意:1, 参数范围0~1; 2,
注意整数相除结果只保留整数部分
//// view3.backgroundColor = [UIColor colorWithRed:155 / 255.0 green:175 /255.0 blue:194 / 255.0 alpha:1.0];
//
// // 透明度
//// view3.alpha = 0.2;
//
// // 标签
// // 注意,
标签值一般设置较大, 因为较小的tag已经被系统占用
//// view3.tag = 10001;
//
//// // frame - 设置坐标及尺寸
//// view3.frame = CGRectMake(100, 100, 20, 20);
////
//// // center - 中心坐标
//// view3.center = CGPointMake(150, 150);
//
// // bounds - 设置坐标及尺寸 -
坐标相对于自身
//// view3.bounds = CGRectMake(10, 10, 200, 200);
//
//// view2.bounds = CGRectMake(10, 0, 200, 200);
//// view2.bounds = CGRectMake(0, 30, 200, 200);
//// view2.bounds = CGRectMake(10, 30, 200, 200);
//
//
// // 视图层级操作
// UIView *view4 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
// view4.backgroundColor = [UIColor blueColor];
// view4.tag = 10002;
// [self.view addSubview:view4];
// [view4 release];
//
//// [self.view insertSubview:view4 aboveSubview:view1];
//// [self.view insertSubview:view4 belowSubview:view1];
//// [self.view insertSubview:view4 atIndex:1];
//
// // 实用方法,
将某一视图移到最前端
//// [self.view bringSubviewToFront:view1];
// // 将某一视图从父视图上移除
//// [view4 removeFromSuperview];
//
// // 隐藏view及子视图 -
默认关闭
//// view2.hidden = NO;
//
// // 计时器
// // 参数1:时间
// // 参数2:可填写方法所在的对象
// // 参数3:定时进入的处理方法
// // 参数4:nil
// // 参数5:是否重复计时
// [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
UILabel *label = [[UILabel
alloc] initWithFrame:CGRectMake(50, 50, 100, 130)];
label.backgroundColor = [UIColor
whiteColor];
//
显示内容
label.text =
@"庆春儿庆春儿庆春儿庆春儿庆春儿庆春儿庆春儿庆春儿庆春儿庆春儿庆春儿庆春儿";
//
文字颜色
label.textColor = [UIColor
blueColor];
//
文字大小
label.font = [UIFont
systemFontOfSize:27.0];
// 加粗并设置文字大小
label.font = [UIFont
boldSystemFontOfSize:27.0];
//
对齐方式
label.textAlignment =
NSTextAlignmentRight;
//
显示行数
//
注意, 要label高度足够
// 当赋值为0时,
代表自动分配行数
label.numberOfLines = 3;
// 断行模式
省略号放在哪
label.lineBreakMode =
NSLineBreakByTruncatingMiddle;
//
阴影颜色
label.shadowColor = [UIColor
yellowColor];
//
阴影偏移量
label.shadowOffset =
CGSizeMake(2, 3);
[self.view
addSubview:label];
[label release];
//
输入框
// UITextField *field = [[UITextField alloc] initWithFrame:CGRectMake(150, 50, 100, 50)];
UITextField *field = [[UITextField
alloc] initWithFrame:CGRectMake(label.frame.origin.x
+ label.frame.size.width + 20, label.frame.origin.y,
100, 50)];
field.backgroundColor = [UIColor
whiteColor];
// text属性可读可写,
当读的时候可获取用户输入内容
// field.text = @"请输入";
field.placeholder =
@"请输入";
//
清除按钮
field.clearButtonMode =
UITextFieldViewModeAlways;
//
密文输入
field.secureTextEntry =
YES;
//
键盘模式
field.keyboardType =
UIKeyboardTypeDefault;
//
是否允许输入 - 默认允许
// field.enabled = NO;
// 允许开始输入时清除内容
field.clearsOnBeginEditing =
YES;
// return按键的模式
field.returnKeyType =
UIReturnKeyNext;
//
边框样式
field.borderStyle =
UITextBorderStyleRoundedRect;
[self.view
addSubview:field];
[field release];
UIButton *button = [UIButton
buttonWithType:UIButtonTypeCustom];
button.frame =
CGRectMake(200, 200, 50, 50);
button.backgroundColor = [UIColor
brownColor];
// button的核心方法
[button addTarget:self
action:@selector(buttonAction:)
forControlEvents:UIControlEventTouchUpInside];
//
移除button的处理方法
// [button removeTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
//
设置文字
[button setTitle:@"登陆"
forState:UIControlStateNormal];
//
设置文字颜色
[button setTitleColor:[UIColor
blueColor] forState:UIControlStateNormal];
[self.view
addSubview:button];
}
// 点击button触发此方法
- (void)buttonAction:(id)sender
{
// if (sender == button1) {
// <#statements#>
// }
self.view.backgroundColor = [UIColor
colorWithRed:(arc4random() % 256) / 255.0
green:(arc4random() % 256) / 255.0
blue:(arc4random() % 256) / 255.0
alpha:1.0];
}
- (void)timerAction
{
// UIView *view = [self.view viewWithTag:10002];
// view.backgroundColor = [UIColor blackColor];
self.view.backgroundColor = [UIColor
colorWithRed:(arc4random() % 256) / 255.0
green:(arc4random() % 256) / 255.0
blue:(arc4random() % 256) / 255.0
alpha:1.0];
}
- (void)didReceiveMemoryWarning {
[super
didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
相关文章推荐
- IOS UI 01 课堂笔记 -label
- 使用yuicompressor-maven-plugin插件压缩JS和CSS静态资源
- UILabel: 如何可以更改除底部外的所有边框?
- Android 异步更新UI----handler+thread
- WebKit之CSSValue的继承关系
- JSP利用过滤器解决request中文乱码问题
- JavaSe String,StringBuffer,StringBuilder 简要区别(随记一)
- iOS环信3.0集成 (二)UI文件集成
- iOS多线程开发——NSOperation/NSOperationQueue浅析
- 使用Fluent API进行属性映射【Code-First系列】
- leetcode -- Permutation Sequence -- 重点
- APUE学习记录——进程环境
- Company BDui 面试 笔试 : 从10个已按从大到小排列好的数组中,求top 15个最大的数
- 62 You have enabled backup optimization in RMAN. You issue the following RMAN command to configure a
- HDU 1005:Number Sequence【规律】
- PyQt5系列教程(二)利用QtDesigner设计UI界面
- hdu 3397 Sequence operation 线段树
- ZOJ 3293 Simple Sequence
- 1801: xue姐的小动物【排序】
- iOS UIView(UIButton)设置圆角和边框