self.title = @"My really looooong title";But if the title is too long as above, the title gets truncated.
Changing the font of the title to a smaller size can make the full text to appear on the title bar.
To do so, you would have to create a custom UILabel.
This is what I did -- (should go under viewDidLoad)
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
[label setFont:[UIFont boldSystemFontOfSize:12.0]];
[label setText:@"My really looooong title";
[label setTextColor:[UIColor whiteColor]];
[self.navigationController.navigationBar.topItem setTitleView:label];
[label release];
Now, there is one important item to keep in mind.
If you are pushing viewcontrollers which are using custom UILabel for its title, you cannot have the page transition animations enabled.
[self.navigationController pushViewController:view2 animated:NO];If you have "animated:YES", the animation causes the custom UILabel to disappear.
UPDATE:
I have upgraded to iPhone OS 3.0 and trying to do the above did not give me the results I wanted. It may still work for you, but for my purposes the title was disappearing. So, in version 3.0 you should use the following code to have custom titles working properly.
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
label.font = [UIFont boldSystemFontOfSize:14.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor whiteColor];
self.navigationItem.titleView = label;
label.text = [dataItem objectForKey:@"title"];
[label release];
-도시
Thanks! This worked when all the other solutions I came across didn't give me the results I wanted. Just a comment, the second last line in the updated text can be any text object. I got of course got an error initially because I didn't have a "dataItem" object.
ReplyDelete