메뉴 건너뛰기

app

[XCODE] 네비게이션바 오른쪽 버튼 및 웹뷰 리사이징

박영식2012.04.23 06:18조회 수 4036댓글 0

    • 글자 크기
네비게이션 컨트롤러가 있는 곳에 타이틀바를 넣고, 오른쪽에 버튼을 추가하는 코드이다.

UIBarButtonItem *settingsButton = [[UIBarButtonItem alloc] initWithTitle:@"신청"
                                                                       style:UIBarButtonItemStylePlain target:self action:@selector(apply:)];
    self.navigationItem.rightBarButtonItem = settingsButton; -(void)apply:(id)sender { }
물론 액션은 위와 같이 정의하고, h파일에 선언하는 것을 잊으면 안된다.


기본 상태에서 웹뷰를 넣으면, 사이트가 원래 크기로 나온다.

[_webView setScalesPageToFit:YES];

위의 코드를 넣어주면, 웹뷰가 화면 크기에 맞게 작아지며, 투 핑거 제스쳐를 이용해 리사이징이 가능하다.


날짜의 형식을 넣는 건 아래와 같다.

    NSString * theDateString;
   
    NSDate * aDate;
    aDate=[[NSDate alloc]init];
   
    NSDateFormatter * aDateFormatter;
    aDateFormatter=[[NSDateFormatter alloc] init];
    [aDateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
    [aDateFormatter setDateFormat:@"MM-dd-yyyy"];
   
    theDateString=@"01-27-2012";
    aDate=[aDateFormatter dateFromString:theDateString];

위의 MM-dd-yyyy로 하고, 01-27-2012로 해야 제대로 된 날짜를 얻을 수 있다. mm을 소문자로 쓰면, 모두 1월로 나오거나, 12월로 나오는 어처구니 없는 상황을 겪을 수도 있다.

NSDateFormatter * dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    //[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    NSString *articleDateString = [dateFormatter stringFromDate:aDate];

활용할 때는 역시 NSDateFormatter를 사용하며 스타일 정의를 통해 위와 같이 NSString으로 빼내면, Jan 27, 2012 식으로 나온다.
주석처리한 setTimeStyle의 경우 시간도 나오게할 수 있다. 값의 정의에 대해서는 아직 쓰지 않아 찾아보지 않았다. 시간도 필요하면, 정의 부터 찾아보면 되겠다. NSDateFormatterMedumStyle은 00:00:00 AM 식으로 나온다.


박영식 (비회원)
    • 글자 크기

댓글 달기

박영식
2006.06.18 조회 2524
박영식
2005.03.25 조회 2254
박영식
2003.12.25 조회 4052
박영식
2003.12.19 조회 3612
박영식
2003.11.05 조회 17690
박영식
2003.11.05 조회 2420
박영식
2003.11.05 조회 2627
박영식
2003.11.05 조회 2326
박영식
2003.11.05 조회 2363
박영식
2003.11.05 조회 3387
박영식
2002.06.14 조회 2732
박영식
2002.04.18 조회 3538
박영식
2002.04.18 조회 3435
첨부 (0)
위로