日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

IOS开发之UIView

發布時間:2025/5/22 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IOS开发之UIView 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>



#import "AppDelegate.h"


@interface AppDelegate ()


@end


@implementation AppDelegate



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

? ? // Override point for customization after application launch.

? ? //1.創建window,設置frame坐標是(0,0)大小是屏幕大小

? ? //[UIScreen mainScreen].bounds]bounds的類型是CGRect;

? ? //xy值是0wh分別是屏幕的寬度和屏幕的高度

? ? _window = [[UIWindow alloc] initWithFrame:

?? ? ? ? ? ? ? [UIScreen mainScreen].bounds];

? ? //2.設置背景顏色

? ? [_window setBackgroundColor:[UIColor blackColor]];

?? ?

? ? //在這兒來創建界面

? ? //==============UIView=============

? ? //UIView是所有視圖類直接或者間接的父類,UIView所有的屬性和方法其他視圖類都有

??

? ? //(1)創建一個UIView對象:

? ? UIView *view1 = [[UIView alloc] init];

?? ?

? ? //(2)frame屬性:

? ? //視圖想要想要顯示在界面上,必須設置frame屬性,告訴系統顯示的位置和大小;

?? //frame屬性中的坐標是相對坐標,將當前視圖添加到哪個視圖上,就是相對于哪個視圖的坐標

? ? //OC中所有的結構體都對應一個make方法來快速的創建結構體變量

? ? [view1 setFrame:CGRectMake(0,20,200 ,100)];

? ? //(3)設置背景顏色(通過類方法創建顏色)

? ? [view1 setBackgroundColor:[UIColor cyanColor]];

? ? //(4)將這個視圖對象view1添加到指定的視圖上

? ? [_window addSubview:view1];

?? ?

? ? [view1 setTag:11];

?? ?

?? ?

?? ?

?? ?

? ? //=============再創建一個View==================

? ? //(1)創建一個UIView對象,并且設置其frame

? ? UIView *view2 = [[UIView alloc]initWithFrame:

? ? CGRectMake(10, 30, 50, 50)];

?? ?

? ? //(2)設置背景顏色

? ? [view2 setBackgroundColor:[UIColor redColor]];

?? ?

? ? //(3)將視圖添加到另外一個視圖上

? ? //_windowview2的父視圖,view2就是_window的子視圖

? ? [_window addSubview:view2];

?? ?

? ? //(4)設置tag:

? ? //作用:a.父視圖通過tag值獲取指定的視圖,如果不設置所有視圖的tag值都是0

? ? //b.

? ? [view2 setTag:10];

?? ?

?? ?

?? ?

?? ?

? ? //3.設置為主窗口并顯示

? ? [_window makeKeyAndVisible];

?? ?

?? ?

?? ?

? ? return YES;

}


- (void)applicationWillResignActive:(UIApplication *)application {


? ? //1.通過tag值去獲取當前視圖上的子視圖;

? ? [[_window viewWithTag:10] setBackgroundColor:[UIColor greenColor]];

?? ?

? ? //2.獲取當前視圖上的所有子視圖

? ? NSArray *viewArray = [_window subviews];

? ? NSLog(@"%@",viewArray);

? ? //遍歷數組中所有的視圖

? ? for (UIView *view in viewArray) {

?? ? ? ?

? ? ? ? if (view.tag == 11) {

?? ? ? ? ? ?

? ? ? ? ? ? [view setBackgroundColor:[UIColor yellowColor]];

?? ? ? ?

? ? ? ? }else if(view.tag == 10){

? ? ? ? ? ?

? ? ? ? ? ? view.backgroundColor = [UIColor whiteColor];

?? ? ? ? ? ?

? ? ? ? }

? ? }

?? ?

}


- (void)applicationDidEnterBackground:(UIApplication *)application {

? ? // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

? ? // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}


- (void)applicationWillEnterForeground:(UIApplication *)application {

? ? // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}


- (void)applicationDidBecomeActive:(UIApplication *)application {

? ? // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}


- (void)applicationWillTerminate:(UIApplication *)application {

? ? // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}


@end


轉載于:https://my.oschina.net/luhoney/blog/653093

總結

以上是生活随笔為你收集整理的IOS开发之UIView的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。