iOS2012. 9. 4. 16:25

iOS에서 네비게이션바에 이미지를 설정하는 함수가 생겼다.


setBackgroundImage:forBarMetrics:


이 함수로 이미지만 설정하면 간단하나, 문제는 iOS4이하에서의 설정방법


따라서 아래와 같이 설정하면 iOS 버전과 관련 없이 모두 적용할 수 있다.


viewDidLoad 같은 곳에서 설정하면 됨


 UIColor *color = [UIColor colorWithRed:0.94 green:0 blue:0.44 alpha:1.0];

    self.navigationController.navigationBar.tintColor = color;

UIImage *imageNavCon = [UIImage imageNamed:@"background.png"];

if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])

    {

        [self.navigationController.navigationBar setBackgroundImage:imageNavConforBarMetrics:UIBarMetricsDefault];

    }

else {

[self.navigationController.navigationBar insertSubview:[[[UIImageView allocinitWithImage:imageNavCon]autoreleaseatIndex:0]; 

}

Posted by 다오나무
영삼이의 IT정보2012. 6. 14. 12:29
Posted by 다오나무