Contents

Develop
2013.04.23 18:07

[ios] UILabel top alignㅎㅎ

조회 수 23850 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
나를 귀찮게 하는 아이폰의 api 부재
레이블에 대해서 문자의 가로정렬은 쉽게 되지만, 세로정렬은 sdk 의 속성을
눈 씻고 찾아봐도 찾을 수 없어 구걸신에게 또 구걸하여 아래와 같은 코드를 얻었다.

개념은 NSString의 sizeWithFont 메소드를 사용하여 실제로 그려질 크기를 손쉽게 구한 후에
이 값을 UILabel의 frame에 대입해주는 것이다.

아래 예제는 top 정렬 뿐 아니라 bottom 정렬도 가능한 예제이다.
- (void)setUILabel:(UILabel *)myLabel
  withMaxFrame:(CGRect)maxFrame
  withText:(NSString *)theText
  usingVerticalAlign:(int)vertAlign
{

  CGSize stringSize =
    [theText sizeWithFont:myLabel.font
      constrainedToSize:maxFrame.size
      lineBreakMode:myLabel.lineBreakMode];
 
  switch (vertAlign) {
    case 0: // vertical align = top
      myLabel.frame = CGRectMake(myLabel.frame.origin.x, 
        myLabel.frame.origin.y, 
        myLabel.frame.size.width, 
        stringSize.height);
      break;

    case 1: // vertical align = middle
      // don't do anything,
      // lines will be placed in vertical middle by default
      break;

    case 2: // vertical align = bottom
      myLabel.frame = CGRectMake(myLabel.frame.origin.x, 
        (myLabel.frame.origin.y + myLabel.frame.size.height)
         - stringSize.height, 
        myLabel.frame.size.width, 
        stringSize.height);
      break;
  }

  myLabel.text = theText;
}

참조: http://discussions.apple.com/thread.jspa?messageID=8322622

?

  1. [vb] 문자열에서 태그 제거함수 (Visual Basic)

    Date2013.04.23 CategoryDevelop Byhooni Views25597
    Read More
  2. [ios] 아이폰 개발 총정리..

    Date2013.04.23 CategoryDevelop Byhooni Views25119
    Read More
  3. [c++] MD5 구현 소스.. 퍼움..

    Date2013.04.23 CategoryDevelop Byhooni Views25108
    Read More
  4. 영어. 외우면 도움되는 필수영어회화 표현

    Date2013.09.09 CategoryEtc Byhooni Views24923
    Read More
  5. [doc] 정보보호이론 강의자료 (중앙대꺼..)

    Date2013.04.23 CategoryPPT Byhooni Views24840
    Read More
  6. [web] 제로보드 XE 템플릿에서 if문에 대해서 알아봅시다

    Date2013.08.16 CategoryEtc Byhooni Views24737
    Read More
  7. [c] 다중연결 서버 만들기 #4 - thread 사용

    Date2013.04.23 CategoryDevelop Byhooni Views24729
    Read More
  8. [ios] 아이폰 개발 따라하기 ㅋㅋㅋ

    Date2013.04.23 CategoryEtc Byhooni Views24725
    Read More
  9. GCM 사용하기 2 (단말에 GCM 구현하기)

    Date2013.07.06 CategoryDevelop Byhooni Views24652
    Read More
  10. Polynomial time 이란? ㅋㅋ

    Date2013.04.23 CategoryAlgorithm Byhooni Views24649
    Read More
  11. [pdf] GPS의 동작 원리 ㅎㅎ

    Date2013.04.23 CategoryDevelop Byhooni Views24582
    Read More
  12. 러시아 페인트공 알고리즘에 대해..

    Date2013.04.23 CategoryAlgorithm Byhooni Views24518
    Read More
Board Pagination Prev 1 ... 7 8 9 10 11 12 13 14 15 16 ... 99 Next
/ 99