UI第一天
来源:互联网 发布:用户运营数据挖掘 编辑:程序博客网 时间:2024/06/06 04:31
1.UIView和所有继承自UIView的子类的对象创建的过程
/*
1.初始化UIView的对象UIView *MyView = [[UIView alloc] 初始化方法];
2.设置属性,颜色尺寸等
3.把视图加载到窗口上
4.释放对象
*/
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;
};
CGPoint origin;
CGSize size;
};
typedef structCGRect CGRect;
//origin起始点
struct CGPoint {
CGFloat x;
CGFloat y;
};
CGFloat x;
CGFloat y;
};
typedef structCGPoint CGPoint;
//尺寸大小
struct CGSize {
CGFloat width;
CGFloat height;
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)点,子视图根据新的坐标原点发生变化
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 = [UIColorbrownColor];
aview.alpha = 0.8;
//superview 获取父视图
[dview superview].backgroundColor = [UIColorbrownColor];
//subviews 获取所有子视图
NSArray *arr = [aviewsubviews];
//提前给视图添加一个标签
aview.tag = 100;
//利用tag值取出子视图(必须是标记视图的父视图调用viewWithTag方法)
aview.tag = 100;
//利用tag值取出子视图(必须是标记视图的父视图调用viewWithTag方法)
[self.windowviewWithTag:100].backgroundColor = [UIColorblackColor];
3.UILabel
UILabel *aLable = [[UILabelalloc] initWithFrame:CGRectMake(50,50, 100, 100)];
aLable.text = @"Application windows are expected to have a root view controller at the end of application launch";
//文字,背景颜色
aLable.textColor = [UIColorredColor];
aLable.backgroundColor = [UIColorbrownColor];
aLable.textAlignment = NSTextAlignmentCenter;
//显示行数
aLable.numberOfLines = 0;
//阴影的位
aLable.shadowColor = [UIColorblackColor];
aLable.shadowOffset = CGSizeMake(2, 1);
//改变字体属性
//打印出已安装的所有字体
NSArray *arr = [UIFontfamilyNames];
for (id objin arr) {
NSLog(@"%@",obj);
}
aLable.font = [UIFontfontWithName:@" Zapfino"size:20];
//修改字体的大写
aLable.font = [UIFontsystemFontOfSize:24];
//断行lineBreakMode
aLable.lineBreakMode = NSLineBreakByTruncatingMiddle;//以单词为单位换⾏行
//断行形式
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" */
} NS_ENUM_AVAILABLE_IOS(6_0);
[self.windowaddSubview:aLable];
[aLable release];
(4).拓展(明天补充)
UITextField *loginText = [[UITextFieldalloc] initWithFrame:CGRectMake(140,100, 150, 25)];
[self.windowaddSubview:loginText];
loginText.borderStyle = UITextBorderStyleRoundedRect;//边框类型
loginText.placeholder = @"请输入密码";//默认显示的文字
[self.windowaddSubview:loginText];
loginText.borderStyle = UITextBorderStyleRoundedRect;//边框类型
loginText.placeholder = @"请输入密码";//默认显示的文字
loginText.clearButtonMode = UITextFieldViewModeWhileEditing;//编辑的删除按钮
UIButton * btn = [[UIButtonalloc] initWithFrame:CGRectMake(50,400, 50, 25)];
[btn setTitle: @"注册"forState: UIControlStateNormal];//设置默认状态下的文字
[btn setTitleColor:[UIColorblueColor] forState:UIControlStateNormal];//设置默认状态下的颜色
btn.titleLabel.font = [UIFontsystemFontOfSize: 14.0];
[self.windowaddSubview: btn];
[btn setTitle: @"注册"forState: UIControlStateNormal];//设置默认状态下的文字
[btn setTitleColor:[UIColorblueColor] forState:UIControlStateNormal];//设置默认状态下的颜色
btn.titleLabel.font = [UIFontsystemFontOfSize: 14.0];
[self.windowaddSubview: btn];
0 0
- UI第一天
- UI第一天UIView
- UI的第一天
- UI第一天
- UI 第一天
- UI基础总结第一天
- UI第一天学习总结
- UI基础学习第一天
- PS UI学习第一天
- 仿爱奇艺UI界面(第一天)
- iOS-学习笔记-UI-第一天
- UI第一天:UIView及其⼦类
- UI学习第一天UIView 和UILabel
- UI基础第一天(知识点)
- UI基础第一天(代码)
- 学习笔记 Bootstrap 第一天--UI框架
- 第一天关于UI设计的小问题
- #Objective - C - UI-design - 第一天 -UIKit框架-UIKit-UIView
- Android Acitivy切换平移动画效果实现
- 【ID搜索】uva12558Egyptian Fractions(HARD version) 埃及分数
- 股票学习(K线)
- Java 里使用 long 类型的数据一定要在数值后面加上 “L”
- Android小记:ViewStub的应用
- UI第一天
- iPad popView封装
- Objective-C 【OC和C的区别-面向对象-有参/无参方法-类和对象】
- tozhuweichong
- Torch7 教程 Supervised Learning CNN
- Python学习资料汇总
- QWT6.0.1+win7下安装说明
- 查看jdk源码的网站
- HDU 4293 Groups(区间dp)