UI第一天
2015-07-27 21:52
615 查看
1.UIView和所有继承自UIView的子类的对象创建的过程
/*
1.初始化UIView的对象
UIView *MyView = [[UIView alloc]
初始化方法];
2.设置属性,颜色尺寸等
3.把视图加载到窗口上
4.释放对象
*/
//子视图的起始点是指的是其[父视图的起始点]开始计算
UIView *aview = [[UIView alloc] initWithFrame:CGRectMake(50,50,200,50)];//x,y,宽,高
aview.backgroundColor = [UIColor blackColor];
[self.window addSubview:aview];//把视图加载到窗口上,那么window就是view的父视图
[aview release];
//============================
2.UIView 的frame,center,bounds属性
(1).frame 是CGRect类型,有x,y,宽,高
struct CGRect {
CGPoint origin;
CGSize size;
};
typedef struct
CGRect CGRect;
//origin起始点
struct CGPoint {
CGFloat x;
CGFloat y;
};
typedef struct
CGPoint CGPoint;
//尺寸大小
struct CGSize {
CGFloat width;
CGFloat height;
};
(2).center代表中心点
center.x = frame.origin.x + frame.size.width/2;
center.y = frame.origin.y + frame.size.height/2;
(3).bounds属性
/*bounds 默认的起始点是(0,0)
宽高和frame的相同,修改父视图的bounds就是
1修改了子视图的坐标系,
2.父视图没有变化,
3.原来的坐标系的(0,0)点变化,如改成了(10,10),即改变bounds
4.寻找现在的(0,0)点,子视图根据新的坐标原点发生变化
*/
aview.bounds =
CGRectMake(10,
10, 100, 100);//这里aview是其他两个子类view的属性
子类视图将会向左向上分别移动10个单位
2.常用属性
//NSStringFrom...把不同类型的数据转成NSString
NSLog(@"%@",NSStringFromCGPoint(aview.center ));
//hidden视图隐藏,如果该视图被隐藏其子视图也被隐藏
aview.hidden =
YES;
//alpha透明度,设置视图的透明度0-1之间,1是不透明,依次递减,子视图的透明度随其父视图的透明度而改变
aview.alpha =
0.8;
//superview 获取父视图
[dview superview].backgroundColor = [UIColor
brownColor];
//subviews
获取所有子视图
NSArray *arr = [aview
subviews];
//提前给视图添加一个标签
aview.tag = 100;
//利用tag值取出子视图(必须是标记视图的父视图调用viewWithTag方法)
[self.window
viewWithTag:100].backgroundColor = [UIColor
blackColor];
3.UILabel
UILabel *aLable = [[UILabel
alloc] initWithFrame:CGRectMake(50,
50, 100,
100)];
aLable.text =
@"Application windows are expected to have a root view controller at the end of application launch";
[align=left] //文字,背景颜色[/align]
aLable.textColor = [UIColor
redColor];
aLable.backgroundColor = [UIColor
brownColor];
aLable.textAlignment =
NSTextAlignmentCenter;
[align=left] //显示行数[/align]
aLable.numberOfLines =
0;
[align=left] //阴影的位[/align]
aLable.shadowColor = [UIColor
blackColor];
aLable.shadowOffset =
CGSizeMake(2,
1);
[align=left] //改变字体属性[/align]
[align=left] //打印出已安装的所有字体[/align]
NSArray *arr = [UIFont
familyNames];
for (id obj
in arr) {
[align=left] NSLog(@"%@",obj);[/align]
[align=left] } [/align]
aLable.font = [UIFont
fontWithName:@" Zapfino"
size:20];
[align=left] //修改字体的大写[/align]
aLable.font = [UIFont
systemFontOfSize:24];
[align=left] //断行lineBreakMode[/align]
aLable.lineBreakMode =
NSLineBreakByTruncatingMiddle;//以单词为单位换⾏行
[align=left] //断行形式[/align]
typedef
NS_ENUM(NSInteger, NSLineBreakMode) { /* What to do with long lines */
NSLineBreakByWordWrapping =
0, /* Wrap at word boundaries, default */
NSLineBreakByCharWrapping,
/* Wrap at character boundaries */
NSLineBreakByClipping,
/* Simply clip */
NSLineBreakByTruncatingHead,
/* Truncate at head of line: "...wxyz" */
NSLineBreakByTruncatingTail,
/* Truncate at tail of line: "abcd..." */
NSLineBreakByTruncatingMiddle
/* Truncate middle of line: "ab...yz" */
[align=left] } NS_ENUM_AVAILABLE_IOS(6_0);[/align]
[align=left] [/align]
[self.window
addSubview:aLable];
[align=left] [aLable release];[/align]
[align=left] [/align]
[align=left]
[/align]
[align=left](4).拓展(明天补充)[/align]
UITextField *loginText = [[UITextField
alloc] initWithFrame:CGRectMake(140,
100, 150,
25)];
[self.window
addSubview:loginText];
loginText.borderStyle =
UITextBorderStyleRoundedRect;//边框类型
loginText.placeholder =
@"请输入密码";//默认显示的文字
loginText.clearButtonMode =
UITextFieldViewModeWhileEditing;//编辑的删除按钮
UIButton * btn = [[UIButton
alloc] initWithFrame:CGRectMake(50,
400, 50,
25)];
[btn setTitle:
@"注册"
forState: UIControlStateNormal];//设置默认状态下的文字
[btn setTitleColor:[UIColor
blueColor] forState:UIControlStateNormal];//设置默认状态下的颜色
btn.titleLabel.font = [UIFont
systemFontOfSize:
14.0];
[self.window
addSubview: btn];
/*
1.初始化UIView的对象
UIView *MyView = [[UIView alloc]
初始化方法];
2.设置属性,颜色尺寸等
3.把视图加载到窗口上
4.释放对象
*/
//子视图的起始点是指的是其[父视图的起始点]开始计算
UIView *aview = [[UIView alloc] initWithFrame:CGRectMake(50,50,200,50)];//x,y,宽,高
aview.backgroundColor = [UIColor blackColor];
[self.window addSubview:aview];//把视图加载到窗口上,那么window就是view的父视图
[aview release];
//============================
2.UIView 的frame,center,bounds属性
(1).frame 是CGRect类型,有x,y,宽,高
struct CGRect {
CGPoint origin;
CGSize size;
};
typedef struct
CGRect CGRect;
//origin起始点
struct CGPoint {
CGFloat x;
CGFloat y;
};
typedef struct
CGPoint CGPoint;
//尺寸大小
struct CGSize {
CGFloat width;
CGFloat height;
};
(2).center代表中心点
center.x = frame.origin.x + frame.size.width/2;
center.y = frame.origin.y + frame.size.height/2;
(3).bounds属性
/*bounds 默认的起始点是(0,0)
宽高和frame的相同,修改父视图的bounds就是
1修改了子视图的坐标系,
2.父视图没有变化,
3.原来的坐标系的(0,0)点变化,如改成了(10,10),即改变bounds
4.寻找现在的(0,0)点,子视图根据新的坐标原点发生变化
*/
aview.bounds =
CGRectMake(10,
10, 100, 100);//这里aview是其他两个子类view的属性
子类视图将会向左向上分别移动10个单位
2.常用属性
//NSStringFrom...把不同类型的数据转成NSString
NSLog(@"%@",NSStringFromCGPoint(aview.center ));
//hidden视图隐藏,如果该视图被隐藏其子视图也被隐藏
aview.hidden =
YES;
//alpha透明度,设置视图的透明度0-1之间,1是不透明,依次递减,子视图的透明度随其父视图的透明度而改变
aview.alpha =
0.8;
//superview 获取父视图
[dview superview].backgroundColor = [UIColor
brownColor];
//subviews
获取所有子视图
NSArray *arr = [aview
subviews];
//提前给视图添加一个标签
aview.tag = 100;
//利用tag值取出子视图(必须是标记视图的父视图调用viewWithTag方法)
[self.window
viewWithTag:100].backgroundColor = [UIColor
blackColor];
3.UILabel
UILabel *aLable = [[UILabel
alloc] initWithFrame:CGRectMake(50,
50, 100,
100)];
aLable.text =
@"Application windows are expected to have a root view controller at the end of application launch";
[align=left] //文字,背景颜色[/align]
aLable.textColor = [UIColor
redColor];
aLable.backgroundColor = [UIColor
brownColor];
aLable.textAlignment =
NSTextAlignmentCenter;
[align=left] //显示行数[/align]
aLable.numberOfLines =
0;
[align=left] //阴影的位[/align]
aLable.shadowColor = [UIColor
blackColor];
aLable.shadowOffset =
CGSizeMake(2,
1);
[align=left] //改变字体属性[/align]
[align=left] //打印出已安装的所有字体[/align]
NSArray *arr = [UIFont
familyNames];
for (id obj
in arr) {
[align=left] NSLog(@"%@",obj);[/align]
[align=left] } [/align]
aLable.font = [UIFont
fontWithName:@" Zapfino"
size:20];
[align=left] //修改字体的大写[/align]
aLable.font = [UIFont
systemFontOfSize:24];
[align=left] //断行lineBreakMode[/align]
aLable.lineBreakMode =
NSLineBreakByTruncatingMiddle;//以单词为单位换⾏行
[align=left] //断行形式[/align]
typedef
NS_ENUM(NSInteger, NSLineBreakMode) { /* What to do with long lines */
NSLineBreakByWordWrapping =
0, /* Wrap at word boundaries, default */
NSLineBreakByCharWrapping,
/* Wrap at character boundaries */
NSLineBreakByClipping,
/* Simply clip */
NSLineBreakByTruncatingHead,
/* Truncate at head of line: "...wxyz" */
NSLineBreakByTruncatingTail,
/* Truncate at tail of line: "abcd..." */
NSLineBreakByTruncatingMiddle
/* Truncate middle of line: "ab...yz" */
[align=left] } NS_ENUM_AVAILABLE_IOS(6_0);[/align]
[align=left] [/align]
[self.window
addSubview:aLable];
[align=left] [aLable release];[/align]
[align=left] [/align]
[align=left]
[/align]
[align=left](4).拓展(明天补充)[/align]
UITextField *loginText = [[UITextField
alloc] initWithFrame:CGRectMake(140,
100, 150,
25)];
[self.window
addSubview:loginText];
loginText.borderStyle =
UITextBorderStyleRoundedRect;//边框类型
loginText.placeholder =
@"请输入密码";//默认显示的文字
loginText.clearButtonMode =
UITextFieldViewModeWhileEditing;//编辑的删除按钮
UIButton * btn = [[UIButton
alloc] initWithFrame:CGRectMake(50,
400, 50,
25)];
[btn setTitle:
@"注册"
forState: UIControlStateNormal];//设置默认状态下的文字
[btn setTitleColor:[UIColor
blueColor] forState:UIControlStateNormal];//设置默认状态下的颜色
btn.titleLabel.font = [UIFont
systemFontOfSize:
14.0];
[self.window
addSubview: btn];
相关文章推荐
- CALayer与UIView的关系
- UIView的bounds和frame区别
- uiview
- uiview生命周期
- UIView翻译 (参考)
- iOS 转变UIView到UIImage
- UIView动画
- initWithFrame 和 initWithCoder
- [CS193P] 第六堂課摘要及心得筆記
- 棋盘
- ios实现button变换颜色并可以放大、缩小、旋转
- uiview contentViewmode
- iphone开发小记 基础知识2
- iphone开发小记 基础知识3
- [笔记]I 群聊天记录2012/03/中
- iPhone开发进阶(2) --- iPhone应用程序/项目的构成
- 视图弹出后放大又缩小的动画实现、类似于alertView效果
- iPhone SDK开发:自定义UIAlertView
- IOS开发中的UIScreen、UIView、UIWindow和UIViewController
- retain和copy还有assign的区别,以及引用计数