I have customized the UIBarButtonItem like this:
UIButton *loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
loginBtn.frame = CGRectMake(0, 0, 46.0, 34.0);
[loginBtn setImage:[UIImage imageNamed:@"loginBtn.png"] forState:UIControlStateNormal];
[loginBtn addTarget:self action:@selector(loginPressed:) forControlEvents:UIControlEventTouchUpInside];
[loginBtn setTitle:@"Login" forState:UIControlStateNormal];
UIBarButtonItem *finishedButton = [[UIBarButtonItem alloc] initWithCustomView:loginBtn];
[finishedButton setStyle:UIBarButtonItemStylePlain];
self.navigationItem.rightBarButtonItem = finishedButton;
But now i can not see the title with “Login”, it’s blank on the button, it seems that the “setTitle:” did not work.
Could anybody tell me why? Thx!
setTitle:did work, you just haven’t read the documentation carefully enough. UsesetBackgroundImage:instead ofsetImage:as the latter overridessetTitle:, but the former doesn’t (and that’s what you want). So instead ofwrite
and you should be fine to go.