UIView
UIView
cmd + 1模擬器比例100%
cmd + 2模擬器比例75%
cmd + 3模擬器比例50%
cmd + 4模擬器比例33%
cmd + 5模擬器比例25%
cmd + shift + h 點擊Home鍵
cmd + shift + k 模擬器連接物理鍵盤
cmd + k 隱藏或者顯示虛擬器上的鍵盤
cmd + shift + hh 顯示所有打開的應用程序
cmd + l 鎖屏
刪除應用: 長按應用, 點擊x
cmd + s 截屏
程序的入口是main函數
int main(int argc, char * argv[]) {@autoreleasepool {NSLog(@"程序的入口main函數");//指定程序的代理為AppDelegate//所有和程序相關的操作都是由AppDelegate來處理return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));} }Extension, 延展, 私有方法的聲明和在類內部使用的實例變量
@interface AppDelegate ()@end @implementation AppDelegate -(void)dealloc {[_window release];[super dealloc]; }程序已經完成加載
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {} - (void)applicationWillResignActive:(UIApplication *)application {NSLog(@"程序將要注銷激活");
} - (void)applicationDidEnterBackground:(UIApplication *)application {NSLog(@"程序已經進入后臺"); } - (void)applicationWillEnterForeground:(UIApplication *)application {NSLog(@"程序將要進入前臺"); } - (void)applicationDidBecomeActive:(UIApplication *)application {NSLog(@"程序已經激活"); } - (void)applicationWillTerminate:(UIApplication *)application {NSLog(@"程序將要終止"); }
?UI: User Interface, 用戶界面
?UIWindow, 窗口類, 所有的控件必須放到window上才能顯示, 一個iOS應用至少要有一個窗口, 繼承于UIView
?iOS手機中的坐標系, 不同于數學中的笛卡爾坐標系, 原點在左上角, x軸: 向右越來越大, y軸: 向下越來越大
?與坐標系相關的數據類型
? CGPoint, 結構體, 用于存放一個點的坐標
CGPoint point = CGPointMake(10, 100);NSLog(@"%.lf, %.lf", point.x, point.y);NSLog(@"%@", NSStringFromCGPoint(point));?CGSize, 結構體, 用于存放矩形的寬和高
CGSize size = CGSizeMake(150, 200);NSLog(@"%.lf %.lf", size.width, size.height);NSLog(@"%@", NSStringFromCGSize(size));CGRect, 結構體, 用于存放矩形的位置和大小
CGRect rect = CGRectMake(10, 100, 150, 200);NSLog(@"%.lf %.lf %.lf %.lf", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);NSLog(@"%@", NSStringFromCGRect(rect));?[UIScreen mainScreen] bounds], 主屏幕的大小
?[UIScreen mainScreen], 獲取到主屏幕
?UIScreen, 屏幕類
?? NSLog(@"%@", NSStringFromCGRect([[UIScreen mainScreen] bounds]));?
?屏幕大小(單位:pt, point)
? ? 1, 3g, 3gs, 4, 4s: [320 * 480]
? ? 5, 5s, 5c: [320 * 568]
? ? 6, 6s: [375 * 667]
? ? 6 Plus, 6s Plus: [414 * 736]
?創(chuàng)建一個和屏幕大小一樣的window對象
?? self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];?
UIColor, 顏色類, 繼承于NSObject, 用于展示一種顏色
RGBA, 取值范圍[0, 1]
? UIColor *color = [UIColor colorWithRed:0.656 green:1.000 blue:0.838 alpha:1.000];??
設置背景顏色
? self.window.backgroundColor = [UIColor purpleColor];?
讓當前窗口成為主窗口, 并顯示
?[self.window makeKeyAndVisible];?
? ARC->MRC
? ? 1.gar
? ? 2.strong->retain
? ? 3.重寫dealloc方法
? ? 4.window, autorelease
?UIView, 繼承于UIResponder, 一個矩形區(qū)域, 所有的控件都是繼承于UIView, 用戶在手機上能夠看到的都是UIView或UIView的子類
?創(chuàng)建一個視圖的步驟? ?
1.創(chuàng)建視圖, 并設定位置和大小UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(20, 30, 100, 200)];//2.設置視圖屬性//顏色aView.backgroundColor = [UIColor purpleColor];//是否隱藏aView.hidden = YES;//不透明度aView.alpha = 0.6;//3.添加到window上 [self.window addSubview:aView];//4.釋放視圖[aView release]; UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];redView.backgroundColor = [UIColor redColor];redView.hidden = YES;redView.alpha = 0.7;[self.window addSubview:redView];[redView release];UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];blueView.backgroundColor = [UIColor blueColor];blueView.hidden = YES;blueView.alpha = 0.7;[self.window addSubview:blueView];[blueView release];UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(150, 150, 100, 100)];greenView.backgroundColor = [UIColor greenColor];greenView.hidden = YES;greenView.alpha = 0.7;[self.window addSubview:greenView];[greenView release];隨機位置, 隨機顏色, 創(chuàng)建視圖
UIColor *randomColor = [UIColor colorWithRed:arc4random() % 256 / 255. green:arc4random() % 256 / 255. blue:arc4random() % 256 / 255. alpha:arc4random() % 256 / 255.]; for (NSInteger i = 0; i < 1888; i++) {UIView *view = [[UIView alloc] initWithFrame:CGRectMake(arc4random() % (375 - 10 + 1) / 1. , arc4random() % (667 - 10 + 1) / 1., 10, 10)];view.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255. green:arc4random() % 256 / 255. blue:arc4random() % 256 / 255. alpha:1];[self.window addSubview:view];[view release];}?視圖的層級關系
? ? 1.越晚添加的視圖, 顯示在最前面
? ? 2.一個視圖只能有一個父視圖, 但是可以有多個子視圖
? ? 3.一個視圖位置, 是相對于它的父類視圖坐標系計算的
UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 300, 300)];redView.backgroundColor = [UIColor redColor];redView.hidden = NO;redView.alpha = 0.8;[self.window addSubview:redView];[redView release];UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];blueView.backgroundColor = [UIColor blueColor];blueView.hidden = NO;blueView.alpha = 0.7;//超出父視圖部分是否切除, 默認NOblueView.clipsToBounds = YES;[redView addSubview:blueView];[blueView release];UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];greenView.backgroundColor = [UIColor greenColor];greenView.hidden = NO;greenView.alpha = 0.7;[blueView addSubview:greenView];[greenView release]; //父視圖NSLog(@"%@", redView.superview);//子視圖NSLog(@"%@", redView.subviews);NSLog(@"%@", self.window.subviews);center, 基于父視圖坐標系, 視圖中心點在父視圖坐標系中的位置
NSLog(@"%@", NSStringFromCGPoint(redView.center));NSLog(@"%@", NSStringFromCGPoint(blueView.center));frame, 基于父視圖坐標系, 視圖在父視圖坐標系中的位置和大小
NSLog(@"%@", NSStringFromCGRect(redView.frame));NSLog(@"%@", NSStringFromCGRect(blueView.frame));bounds, 基于自身坐標系, 視圖在自身坐標系中的位置和大小, 默認值:{0, 0, w, h}
NSLog(@"%@", NSStringFromCGRect(redView.bounds));redView.bounds = CGRectMake(100, 100, 300, 300);UIView屬性
? ? 1.backgroundColor(默認透明色)
? ? 2.hidden
? ? 3.alpha
? ? 4.clipsToBounds
? ? 5.superView
? ? 6.subViews
? ? 7.center
? ? 8.frame
? ? 9.bounds
?
?
轉載于:https://www.cnblogs.com/OrangesChen/p/4883613.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
- 上一篇: C#中的DataSet添加DataTab
- 下一篇: 联想主板设置光驱启动不了怎么办 联想主板