網頁

2012年4月11日 星期三

xcode custom navigation bar and button


 
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // Do any additional setup after loading the view.

    UIImage *headerImage = [UIImage imageNamed: @"navigationBar.png"];
    [self.navigationController.navigationBar setBackgroundImage:headerImage forBarMetrics:UIBarMetricsDefault];
    
    
    UIImage *backImage = [UIImage imageNamed: @"back.png"];
 UIButton *backButton = [UIButton buttonWithType: UIButtonTypeCustom];
 backButton.frame = CGRectMake(0, 0, 44, 38);
 [backButton setBackgroundImage: backImage forState: UIControlStateNormal];
 [backButton addTarget: self
       action: @selector(popCurrentViewController)
   forControlEvents: UIControlEventTouchUpInside];
 UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithCustomView: backButton];
 self.navigationItem.leftBarButtonItem = back;
    
}
-(void) popCurrentViewController
{
     UIImage *headerImage = [UIImage imageNamed: @"navigationBar.png"];
    [self.navigationController.navigationBar setBackgroundImage:headerImage forBarMetrics:UIBarMetricsDefault];
    
    
    [self.navigationController popViewControllerAnimated: YES];
}
iOS5 StoryBoard

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。