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];
    

}

 

posted @ 2020-07-13 22:15  逆欢  阅读(118)  评论(0编辑  收藏  举报