Date
Sep. 8th, 2024
 
2024年 8月 6日

Post: iOS 入门 011: frame、bounds 与 center

iOS 入门 011: frame、bounds 与 center

Published 12:04 Apr 12, 2012.

Created by @ezra. Categorized in #Programming, and tagged as #iOS.

Source format: Markdown

Table of Content

frame/bounds/center

frame 位置与尺寸属性

  • 控件所在矩形框的位置和尺寸

  • 坐标系原点为父视图的左上角,向右横轴递增,向下纵轴值递增

bounds尺寸属性

  • 控件所在矩形框的位置和尺寸

  • bounds的坐标系原点为自身的左上角,向右横轴递增,向下纵轴值递增

center中心点属性

  • 控件中点的位置,通过center属性设置视图位置更加方便

  • center的坐标系原点为父视图的左上角,向右横轴递增,向下纵轴值递增

使用注意

  • 用frame和center可以修改UIView的位置

  • 用frame和bounds可以修改UIView的尺寸

  • 通常,修改自身位置大小时使用frame,而子视图 (控件) 在设置位置时,会相对父视图的bounds进行设置

通过frame.origin.x和frame.origin.y进行位置操作

e.g.

CGRect rect=_bt.frame;
rect.origin.y +=10;
[_bt setFrame:rect];
Pinned Message
HOTODOGO
The Founder and CEO of Infeca Technology.
Developer, Designer, Blogger.
Big fan of Apple, Love of colour.
Feel free to contact me.
反曲点科技创始人和首席执行官。
程序猿、设计师、奇怪的博主。
苹果死忠、热爱色彩斑斓的世界。
如有意向请随时 与我联系