23.UIView
来源:互联网 发布:潍坊行知学校 宿舍 编辑:程序博客网 时间:2024/05/18 18:44
- UIView
- 介绍
- 位置属性
- 显示设置
- 显示位置
- 追加控件
UIView
介绍
- UIView是组成画面的基本元素,拥有位置属性、一定尺寸的四边形,一般有背景色。
- UIView可以拥有UIView类型的子元素(追加UIView)
- 在iphone应用程序中,应用程序的UIWindow也是UIView的子类
位置属性
UILabel *label = [[UILabel alloc] init]; //frame设置(设置X,Y,高 label.frame = CGRectMake(x, y, w, h); //获取frame的各种值 NSLog(@"x = %f, label.frame.origin.x"); NSLog(@"x = %f, label.frame.origin.y"); NSLog(@"x = %f, label.frame.size.width"); NSLog(@"x = %f, label.frame.size.hight"); //center设置(以label为中心设置X和Y) label.center = CGPointMake(X, Y); //获取center的各种值 NSLog(@"x = %f, label.center.x"); NSLog(@"x = %f, label.center.y");
显示设置
//隐藏控件(但控件是隐藏的,显示出来。否则相反) label.hidden = !label.hidden; //颜色设置 //(1)方法一 label.backgroundColor = [UIColor redColor]; //(2)方法二(自定义颜色,RGB和透明度(0<=1)) label.backgroundColor = [[UIColor alloc] initWithRed:1.0 green:0 blue:0 alpha:0]; //透明度设置(0<=1) label.alpha = 1.0; //控件透明度 label.backgroundColor = [label.backgroundColor colorWithAlphaComponent:1.0]; //设置控件背景颜色透明度 //如果view1 < view2(尺寸大小),隐藏超出view1的view2部分设置 view1.clipsTobounds = YES; //拉申图片(0,0, 1.0,1.0)为原图效果 imageV.layer.contentsRect = CGRectMake(0, 0, 1.0, 0.5); //根据控件内容自动调整大小 [label sizeToFit];
显示位置
//Sanle的会改变图片的尺寸(不会改变比例),其他的只会移动位置 //UIViewContentModeCenter 中心 //UIViewContentModeTop 中上 //UIViewContentModeBottom 中下 //UIViewContentModeLeft 中左 //UIViewContentModeRight 中右 //UIViewContentModeTopLeft 左上 //UIViewContentModeTopRight 右上 //UIViewContentModeBottomLeft 左下 //UIViewContentModeBottomRight 右下 //UIViewContentModeScaleToFill 填充整个View //UIViewContentModeScaleAspectFit 不超出view高/宽度,伸缩至最大尺寸(不改变图片比例) //UIViewContentModeScaleAspectFill 超出view高/宽度,伸缩至最大尺寸(不改变图片比例) imageView.contentMode = UIViewContentModeScaleAspectFit; //以图片为中心点设置x和y imageView.center = CGPointMake(x , y); //旋转90°角 imageV.transform = CGAffineTransformMakeRotation(90 * (M_PI / 180.0)); //扩大/缩放(宽度3.0倍、高度1.0倍) imageV.transform = CGAffineTransformMakeScale(3.0, 1.0); //反转(参数1位:CGAffineTransform 参数2为左右,参数3位上下) imageV.transform = CGAffineTransformScale(imageV.transform, -1.0, -1.0); //平移(若在反转等后面,会直接让他们无效) imageV.transform = CGAffineTransformMakeTranslation(X, Y);
追加控件
//addSubView可以用于View/button/label等等 [self.view addSunbView: 控件]; [button addSunbView: 控件]; //insertSubview可以插入控件,同时设置标签 [self.view insertSubview: 控件 atIndex: NSInteger]; //在控件2 上 插入控件1 [self.view insertSubview: 控件1 aboveSubview: 控件2]; //在控件2 下 插入控件1 [self.view insertSubview: 控件1 belowSubview: 控件2]; //标签1与标签2的控件交换顺序 [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:2];
- 源码:https://yunpan.cn/cSdVKavV8RqFT (提取码:1e6f)
0 0
- 23.UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIVIew
- UIView
- 第八章案例分析
- Python爬虫使用Selenium+PhantomJS抓取Ajax和动态HTML内容
- fragment第二次载入就报错
- C#的百度地图开发 前端显示与定位
- JS中的apply方法和call方法
- 23.UIView
- 根文件系统移植之NFS启动bootloader的设置
- 巧用HashMap去重
- set入门水题(第六届省赛B)
- IntentFilter
- (未完成)C++ 向基类的构造函数传递参数
- ImageButton去边框的问题
- 关于“设计4个线程,其中两个线程对j加1,另外两个线程对j减1”的问题
- .Net Remoting基础(一)