iOS專案開發實戰——理解frame,bounds,center
在iOS介面設計中,設定控制元件的大小往往會用到frame,bounds或者center。我們也同時可以來獲得控制元件的位置資訊。具體程式碼如下:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//檢視;
UIView *view1 = [[UIView alloc] init];
//位置大小;
view1.frame = CGRectMake(20, 30, 100, 200);
//背景顏色;
view1.backgroundColor = [UIColor yellowColor];
//將檢視加入到父檢視中;
[self.view addSubview:view1];
//frame是實際檢視位置與大小,是相對父檢視而言的;
CGFloat x = view1.frame.origin.x;//獲取view的橫座標;
CGFloat y = view1.frame.origin.y;//獲取view的縱座標;
CGFloat width = view1.frame.size.width;//獲取view的寬度;
CGFloat height = view1.frame.size.height;//獲取view的高度;
//bounds是View邊框的位置與大小;
CGFloat xBounds = view1.bounds.origin.x;//獲取view的橫座標;
CGFloat yBounds = view1.bounds.origin.y;//獲取view的縱座標;
CGFloat widthBounds = view1.bounds.size.width;//獲取view的寬度;
CGFloat heightBounds = view1.bounds.size.height;//獲取view的高度;
//center 中心點;
CGFloat xCenter = view1.center.x;
CGFloat yCenter = view1.center.y;
NSLog(@"frame x=%.0f y=%.0f width=%.0f height=%.0f",x,y,width,height);
NSLog(@"bounds x=%.0f y=%.0f width=%.0f height=%.0f",xBounds,yBounds,widthBounds,heightBounds);
NSLog(@"center x=%0.f y=%0.f",xCenter,yCenter);
}
@end
輸出結果如下:
·
github主頁:https://github.com/chenyufeng1991 。歡迎大家訪問!
相關文章
- UIKit Inside: frame bounds position anchorPoint centerUIIDE
- flask 專案開發實戰Flask
- 專案實戰介面開發SpringBootSpring Boot
- iOS – RxSwift 專案實戰記錄iOSSwift
- 小程式雲開發專案實戰
- django專案開發實戰——部落格Django
- 最新Python開發專案實戰(完整)Python
- 淺談設計模式在iOS開發實戰專案中的應用設計模式iOS
- 一本實踐的專案開發《Python專案開發實戰(第2版)》Python
- Web專案開發介紹及實戰專案介紹Web
- iOS開發——專案實戰總結&UITableView效能優化與卡頓問題iOSUIView優化
- Python爬蟲開發與專案實戰pdfPython爬蟲
- Python爬蟲開發與專案實戰(2)Python爬蟲
- Python爬蟲開發與專案實戰(1)Python爬蟲
- git實戰-多分支開發-2022新專案Git
- RabbitMQ專案開發實戰技巧-非常有用MQ
- 3.0 阿里雲大資料專案實戰開發阿里大資料
- Kotlin 入門開發__安卓小專案實戰Kotlin安卓
- WEB實戰:使用MERN技術棧開發專案Web
- 《Node+MongoDB+React 專案實戰開發》已出版MongoDBReact
- React Native iOS混合開發實戰教程React NativeiOS
- IOS開源專案iOS
- python爬蟲實操專案_Python爬蟲開發與專案實戰 1.6 小結Python爬蟲
- tp5+ionic開發微信公眾號專案實戰專案教程
- python專案開發例項-Python專案案例開發從入門到實戰——爬蟲、遊戲Python爬蟲遊戲
- Python爬蟲開發與專案實戰--分散式程式Python爬蟲分散式
- 鴻蒙專案實戰(三):自定義彈窗開發實踐鴻蒙
- Python專案實戰開發最全案例,涵蓋8個開發方向Python
- Appium iOS 測試指令碼開發實戰APPiOS指令碼
- 「Vue實戰」武裝你的專案 - 開發經驗分享Vue
- Python爬蟲開發與專案實戰 4: HTML解析大法Python爬蟲HTML
- GO專案實戰—開發上傳圖片功能 【20220527更新】Go
- 小冊上新:Taro 多端開發實現原理與專案實戰
- 在Flutter專案中開發IOS桌面元件(WidgetExtension)FlutteriOS元件
- dubbo專案實戰
- HarmonyOS 實戰專案
- LittleFox專案實戰
- python實戰專案Python
- 現有Android專案中整合Flutter/Flutter混合開發實戰(一)AndroidFlutter