2012-08-22 4 views
1

아래는 앱 실행 중 탭바 아이콘의 스크린 샷입니다. tabbar barbutton image날짜를 기준으로 탭바 아이콘 변경

아이콘은 27 일을 나타내며 이미지입니다.

오늘 날짜에 따라 동적으로 날짜를 변경할 수있는 방법이 있습니까?

아이폰 SDK는 현재 날짜에 따라 탭 막대 바 버튼 이미지를 동적으로 변경하는 방법이 있습니까?

답변

2

직접 변경해야하지만 오늘 날짜는 매우 쉽습니다.

그리고 그 달의 날짜가 여기에, 매우 간단합니다 당신이 그것을 할 수있는 방법입니다에 geting 그 날짜 :

:

- (UIImage*)todaysImage{ 
    //Get todays date 
    NSDate *today = [NSDate date]; 

    //Get the number using NSDateComponents 
    NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit fromDate:today]; 
    NSInteger day = [components day]; 

    //Load the apropiate image based on the number (this means you have an image for all 31 posible days) 
    //This line also asumes your images are named DayImage-1.png, DayImage-2.png, DayImage-3.png, etc... 
    UIImage *todaysDateImage = [UIImage imageNamed:[NSString stringWithFormat:@"DayImage-%d.png",day]]; 

    return todaysDateImage; 
} 

그럼 당신은 그냥 부를 것이다 yhou 탭 표시 줄에있는 이미지를 설정하기

tabItem.image = [self todaysImage];

비행 중에도 자신의 이미지를 생성 할 수 있으며 매번 생성하지 않아도되므로 캐싱 할 수 있습니다. 당신은 그런 일에 관심이 있다면 이것 좀 있습니다

How to capture UIView to UIImage without loss of quality on retina display

이 방법 대신에 미리로드 할 필요없이 사용하기 위해있는 UIImage 객체로 UIView의 렌더링하는 방법을 보여줍니다 모두 31 개 이미지로 앱.