UIView
来源:互联网 发布:java同步互斥锁notify 编辑:程序博客网 时间:2024/06/11 08:04
//1.UIView创建和使用
// 重要性:
// (1) 常见控件父类或间接父类都是UIView
//UILabel->UIView
//UIImageView->UIView
//UIButton->UIControl->UIView
// (2)自定义控件
// 继承与UIView, view加上其他控件
// (3)使用UIView作为界面布局, UIView作为其他控件的容器
//理解:显示一块矩形区域
UIView *view1 = [[UIViewalloc] init];
view1.frame =CGRectMake(100, 100, 100, 100);
view1.backgroundColor = [UIColorredColor];
[self.viewaddSubview:view1];
//2.常用属性
//位置
//view1.frame
//只改大小,不改位置
view1.bounds =CGRectMake(0, 0, 50, 50);
view1.backgroundColor = [UIColoryellowColor];
//使用tag区分不同控件
//view1.tag = 100;
//设置中心点位置
view1.center =CGPointMake(50, 50);
//是否打开用户交互
//UILabel和UIImageView控件这个值是NO
// 按钮加入到UIImageView没有反应
view1.userInteractionEnabled =YES;
//view设置圆角
view1.layer.cornerRadius = 10;
view1.clipsToBounds =YES;
//是否隐藏
view1.hidden =YES;
view1.hidden =NO;
//透明度
view1.alpha = 0.7;
//3.常用方法
//view1 addSubview:<#(UIView *)#>
//界面上移除控件
//[view1 removeFromSuperview];
//视图层级关系方法
view1.frame =CGRectMake(100, 100, 100, 100);
UIView *view2 = [[UIViewalloc] initWithFrame:CGRectMake(150, 150, 100, 100)];
view2.backgroundColor = [UIColorblueColor];
[self.viewaddSubview:view2];
//放到最前面
[self.viewbringSubviewToFront:view1];
//最后面
[self.viewsendSubviewToBack:view1];
//插入视图
UIView *view3 = [[UIViewalloc] initWithFrame:CGRectMake(125, 125, 100, 100)];
view3.backgroundColor = [UIColorgreenColor];
//[self.view addSubview:view3];
[self.viewinsertSubview:view3 belowSubview:view2];
//属性
//所有子视图
//self.view.subviews
//父视图
//self.view.superview
//4.使用UIView进行控件自定义和界面布局
// view+2个label+一个图片
//原理:只是原理展示, 控件定制需要继承
UIView *photoView = [[UIViewalloc] initWithFrame:CGRectMake(0, 300, 320, 100)];
photoView.backgroundColor = [UIColorlightGrayColor];
[self.viewaddSubview:photoView];
//头像
UIImageView *headImageView = [[UIImageViewalloc] initWithFrame:CGRectMake(20, 20, 60, 60)];
headImageView.image = [UIImageimageNamed:@"defaultHead.png"];
[photoView addSubview:headImageView];
UILabel *label = [[UILabelalloc] initWithFrame:CGRectMake(100, 20, 100, 30)];
label.text =@"风景";
[photoView addSubview:label];
UILabel *timeLabel = [[UILabelalloc] initWithFrame:CGRectMake(100, 60, 100, 30)];
timeLabel.text =@"2014-08-26";
[photoView addSubview:timeLabel];
UITapGestureRecognizer *tap = [[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(dealTap)];
[photoView addGestureRecognizer:tap];
//5.UIView的动画(扩展:仿射变换)
UIImageView *bullet = [[UIImageViewalloc] initWithFrame:CGRectMake(10, 450, 20, 20)];
bullet.image = [UIImageimageNamed:@"bullet.png"];
[self.viewaddSubview:bullet];
// [UIView animateWithDuration:2 animations:^{
// bullet.frame = CGRectMake(300, 450, 50, 50);
// bullet.alpha = 0;
// }];
//
[UIViewanimateWithDuration:4 delay:0options:UIViewAnimationOptionAutoreverseanimations:^{
bullet.frame =CGRectMake(300, 450, 50, 50);
//bullet.alpha = 0;
} completion:^(BOOL finished) {
[bullet removeFromSuperview];
}];
}
-(void)dealTap
{
NSLog(@"点击相册");
}
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIVIew
- UIView
- UIView
- 黑马程序员[android]我的java基础学习日记一
- JavaScript基本技巧
- TQ2440 学习笔记—— 24、IIC 接口
- Python xml.etree.ElementTree 用法
- c++必须在类初始化列表中初始化的几种情况
- UIView
- EditPlus添加asm配置
- LeetCode || Combinations
- UILabe的特殊格式
- Android Studio格式化代码设置和代码风格设置、代码提示键
- C++ Primer : 第十三章 : 拷贝控制示例
- UIButtont特殊样式
- 使用ULTRA LIBRARIAN自动生成SCHLIB和PCBLIB
- 标签栏用库函数