1. 程式人生 > 實用技巧 >UI基礎 UIView

UI基礎 UIView

app m

#import "AppDelegate.h"
#import "ViewController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
// Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; ViewController* first=[[ViewController alloc]init]; self.window.rootViewController=first; return YES; }

UIView m

#import "ViewController.h
" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // self.view.backgroundColor=[UIColor orangeColor]; //UIView 螢幕上的一塊巨型區域 //UIView //1.初始化View UIView* view1 =[[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)]; //2.設定view的背景色
view1.backgroundColor=[UIColor greenColor]; //3.新增 [self.view addSubview:view1]; NSLog(@"%@",self.view); UIView* view2=[[UIView alloc]initWithFrame:CGRectMake(200, 300, 100, 100)]; view2.backgroundColor=[UIColor blueColor]; [self.view addSubview:view2]; //UI View常用的屬性 //1.透明度(0-1) view1.alpha=1; view2.alpha=1; //2.是否隱藏 view1.hidden=NO; //3.中心點 view1.center=self.view.center; //4.tag (標籤) 值 view1.tag=99; // 根據編號找到這個view UIView* resltView = [self.view viewWithTag:99]; resltView.backgroundColor=[UIColor redColor]; // 將一個子檢視放在 前面 resltView [self.view bringSubviewToFront:resltView]; // 將一個檢視移動到 後面 [self.view sendSubviewToBack:resltView]; // 子檢視 自殺 [view1 removeFromSuperview]; }