1. ios UILabel


- ios sdk에서 사용되는 가장 기본적인 클래스중 하나. 어플리케이션내에서 표현되는     짧은 텍스트 들은 대부분 UILabel에 담겨져서 표현된다.

 

 - 샘플코드

<헤더파일에 UILabel *testLabel; 선언 후 사용>


<실행화면>



CGPoint screenSize = CGPointMake([[UIScreen mainScreen]bounds].size.width, [[UIScreen mainScreen]bounds].size.height);


CGPoint는 2차원 배열의 형태로 보통 좌표값을 저장하는데 사용해요.

CGpoint 구조체의 생성은 CGPointMake라는 클래스로 하게되는데


UIScreen 클래스의 mainScreen함수는 사용자 디바이스의 스크린 정보를 가져를 가져오게 되는데 여기서 bounds함수로 디바이스의 크기를 가져올수 있습니다.



// uilabel 프레임 크기 지정

    testLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 300, 200)];


    // view 상에서의 uilabel 중심 좌표 지정

    testLabel.center = CGPointMake(screenSize.x/2, screenSize.y/2);


    // uilabel 배경색 지정

    [testLabel setBackgroundColor: [UIColor grayColor]];


    // uilabel textcolor 지정

    [testLabel setTextColor:[UIColor whiteColor]];


    // uilabel 내용 지정

    [testLabel setText:@"테스트라벨"];


    // 시스템폰트 이외의 다른 폰트를 사용할 해당되는 폰트이름을 fontname 작성한다

    //    [testLabel setFont:[UIFont fontWithName:@"fontname" size:14.f]];


    // 라벨내의 텍스트 정렬 방식

    [testLabel setTextAlignment:NSTextAlignmentCenter];


    // 기본 시스템폰트사용시 글자 크기 변경

    [testLabel setFont:[UIFont systemFontOfSize:12.0f]];


     //메인뷰에 테스트 라벨 추가.

    [self.view addSubview:testLabel];




UILabel은 가장 기본적은 UI 요소 이면서도 가장 많이쓰이는 요소이기도 한 만큼

활용도가 무궁 무진 합니다.

UIanimation을 이용한 여러가지 애니메이션 효과를 적용하면 보다 동적인 UI/UX 디자인을하실 수 있습니다.




WRITTEN BY
arcjeen
ios 관련문의 slimforce@naver.com

,