0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

CGRectについて簡単にまとめてみた

Last updated at Posted at 2023-03-12

CGRectとは

ソースコード

  • CGRectを用いて、適当な位置とサイズにボタンを配置
    • 座標の基準は長方形の左角
Swift
//ボタンの位置とサイズを下記の位置とサイズに編集
rectTestButton.frame = CGRect(x: 20, y: 150, width: 200, height: 100)

Simulator Screen Shot - iPhone 14 Pro - 2023-03-05 at 20.59.39.png

  • ボタンを画面いっぱいに広げる
Swift
//xとyが0以上のとき、指定したView分のwidhやheightは固定されるが、x座標とy座標は動く
rectTestButton.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)

Simulator Screen Shot - iPhone 14 Pro - 2023-03-05 at 20.59.14.png

おわりに

記事に誤り等ございましたらコメント欄にてご指摘ください。

参考記事

CGRect | developer apple documentation

【Swift】CGRectの使い方

【Xcode/Swift】端末の画面サイズ(ポイント)や解像度(ピクセル)、倍率(スケール)を取得する方法

開発環境

  • Xcode-13.4.1
  • Swift version 5.7
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?