728x90

UiView 에 대한 기초적인 내용을 공부하고 적어둔다.


Xcode 상에서 UIView 를 추가하는 그림



//

//  ViewController.m

//  AppView

//

//  Created by jsk005 on 2018. 12. 17..

//  Copyright © 2018 mchello. All rights reserved.

//


#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    

    // UIView 생성

    // [[객체타입 alloc]객체에 따른 생성 방법]

    // [[UIView alloc] initWithFrame:사각형]

    // [parent addSubView:child]; // 화면에 추가하기

    // [child removeFromSuperview]; // 화면에서 삭제하기

    

    // 화면에 보이는 것들의 기본 속성 : 사각형

    // CGRect

    // iOS 좌표계는 좌측 상단이 기준점이다.

    CGRect testRect = CGRectMake(10, 10, 100, 100); // x, y, width, height

    UIView *testView1 = [[UIView alloc] initWithFrame:testRect];

    testView1.backgroundColor = [UIColor redColor];

    [self.view addSubview:testView1];

    

    

    UIView *testView2 = [[UIView alloc] initWithFrame:CGRectMake(50, 150, 100, 100)];

    testView2.backgroundColor = [UIColor blueColor];

    [self.view addSubview:testView2];

    

    // 화면에 추가된 view 삭제하기

    //[testView1 removeFromSuperview];

    

    UIView *testView3 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 30)];

    testView3.backgroundColor = [UIColor redColor];

    [testView2 addSubview:testView3]; // UIView 상에다가 추가하기

    

    // 화면에서 숨기기

    //testView1.hidden = YES;

    testView2.hidden = NO; // YES 설정하면 testView3 같이 안보이게 된다.

    

    // 투명도

    testView1.alpha = 0.3; // alpha 0 hidden YES 같다.

    // hidden fade in, fade out 효과를 없다.

    

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end 


실행결과 


'iOS > Objective-C' 카테고리의 다른 글

objective-c 객체 Type  (0) 2018.12.15
objective-c 함수  (0) 2018.12.12
objective C 변수 타입  (0) 2018.12.09
NSLog  (0) 2018.03.01
모바일 Web을 위한 아이콘 변환 사이트  (0) 2017.05.24
블로그 이미지

Link2Me

,