ios4--UIView的常见属性(尺寸和位置)
//
// ViewController.m
// 08-UIView的常见属性(尺寸和位置)
//
// frame:相对于父控件左上角定位
// bounds:改变长宽,左上角是相对于自己
// center: #import "ViewController.h" @interface ViewController ()
/** label */
@property (nonatomic, weak) UILabel *label; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// 创建UILabel对象
UILabel *label = [[UILabel alloc] init];
// 设置frame (位置和尺寸)
label.frame = CGRectMake(, , , ); //父控件作为原点
// 设置背景颜色
label.backgroundColor = [UIColor yellowColor]; // 添加到控制器的view中
[self.view addSubview:label]; //添加进去了
self.label = label;
} - (IBAction)bounds {
// 改变尺寸 iOS9以后, 中心点不变,向四周延伸
self.label.bounds = CGRectMake(, , , );
} - (IBAction)center {
// 改变位置
// self.label.center = CGPointMake(100, 100); // 显示在最中间
self.label.center = CGPointMake(self.view.frame.size.width * 0.5, self.view.frame.size.height * 0.5); } - (IBAction)changeFrame {
// 方式1
// self.label.frame = CGRectMake(200, 100, 100, 60); // 方式2
self.label.frame = (CGRect){{, }, {, }}; // 方式3
// 结构体是值传递,不是地址传递
// self.label.frame.size.width += 100;
CGRect frame = self.label.frame;
// frame.origin.x -= 100; // 改变x值
// frame.origin.y += 100; // 改变y值
// frame.size.width += 50; // 改变宽度
frame.size.height += ; // 改变高度
self.label.frame = frame; } @end
ios4--UIView的常见属性(尺寸和位置)的更多相关文章
- UIView的常见属性
UIView的常见属性: @interface UIView : UIResponder<NSCoding, UIAppearance, UIAppearanceContainer, UIDyn ...
- iOS开发之UIView的常见属性
1.所有控件都继承自UIView,UIView的常见属性如下: @property(nonatomic,readonly) UIView *superview;获得自己的父控件对象 @property ...
- iOS基础--UIView的常见属性
UIView的常见属性以及方法 @property(nonatomic,readonly) UIView *superview; // 获得自己的父控件对象 @property(nonatomic,r ...
- UIView常见属性总结
一 UIVIew 常见属性 .frame 位置和尺寸(以父控件的左上角为原点(,)) .center 中点 (以父控件的左上角为原点(,)) .bounds 位置和尺寸(以自己的左上角为原点 (,)) ...
- UIScrollView常见属性
什么是UIScrollView •设备的屏幕大小是极其有限的,因此直接展示在用户眼前的内容也相当有限 • •当展示的内容较多,超出一个屏幕时,用户可通过滚动手势来查看屏幕以外的内容 • •普通的UIV ...
- 格而知之2:UIView的autoresizingMask属性探究
UIView的autoresizingMask属性,是用在当一个UIView实例的父控件的尺寸发生变化时,来自动调整UIView实例在父控件中的位置与尺寸的.autoresizingMask属性是一个 ...
- CALayer基本介绍与常见属性
属性框架:QuartzCore CA: CoreAnimation -> 核心动画,所有的核心动画都是添加给layer的! 与UIView的区别: 1.layer负责内容的展示,不接受任何用户交 ...
- UIView的clipsToBounds属性,layoutSubViews及触摸事件传递(默认情况下)总结
一.UIView的clipsToBounds属性 * 默认情况下,超出父控件尺寸范围的子控件还是可见的 * 如果设置父控件的clipsToBounds=YES,就会裁剪掉超出父控件尺寸范围内的子控件, ...
- UIButton 头文件常见属性和方法
UIButton头文件常见属性 1.属性 contentEdgeInsets: default is UIEdgeInsetsZero.设置内容四边距,默认边距为0 @property(nonatom ...
随机推荐
- jstree -- 使用JSON 数据组装成树
概述: 前面主要是html数据,这里主要是json数组 1.格式 jsTree需要一个具体格式JSON数据,在标准的语法没有那个字段是必须的-而是那些是你需要的.请记住你可以获取任何你请求的其他属性, ...
- CAD保存文件为各种格式
<p class="mtext"> 主要用到函数说明:</p><p style="line-height: 0.6;"> & ...
- cmd命令安装、卸载、启动和停止Windows Service
1.运行--〉cmd:打开cmd命令框 2.在命令行里定位到InstallUtil.exe所在的位置 InstallUtil.exe 默认的安装位置是在C:/Windows/Microsoft.NET ...
- chrome://plugins 无法打开的解决方法,同时解决“该网页已屏蔽插件-adobe flash player”
chrome打开想要看视频时提示该网页已屏蔽插件-adobe flash player,在网上查了半天说在chrome plugins里面打开就可以了.可是chrome://plugins 无法打开, ...
- Cmake的介绍和使用 Cmake实践
Cmake的介绍和使用 Cmake实践http://www.cppblog.com/Roger/archive/2011/11/17/160368.html
- 51nod1128 正整数分组V2
[题解] 二分一个最大值,check一下分出来的组数是否小于等于k即可. #include<cstdio> #include<algorithm> #define LL lon ...
- 初学hash
hash定义: Hash,一般翻译做“散列”,也有直接音译为“哈希”的,就是把任意长度的输入(又叫做预映射, pre-image),通过散列算法,变换成固定长度的输出,该输出就是散列值.这种转换是一种 ...
- 实验1“C语言开发环境使用和数据类型、运算符、表达式”总结与体会
一.实验结论 1.判断奇偶 // 程序功能: // 要求用户从键盘输入一个整数,判断其是奇数还是偶数 #include <stdio.h> int main() { int x; prin ...
- 解决Windows Server 2012 R2 Datacenter云服务器无法运行opencv python程序的问题
写了个基于opencv的python程序,pyinstaller 32位机打包后在win7/win10 32/64正常运行,在Windows Server 2012 R2 Datacenter云服务器 ...
- 定时任务-----Springboot中使用Scheduled做定时任务----http://www.cnblogs.com/lirenqing/p/6596557.html
Springboot中使用Scheduled做定时任务---http://www.cnblogs.com/lirenqing/p/6596557.html 已经验证的方案: pom文件加入依赖 < ...