Following is the code which used for back button text
UIButton* backButton = [UIButton buttonWithType:101]; // left-pointing shape!
[backButton addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
[backButton setTitle:parent.title forState:UIControlStateNormal];
if (backButton.frame.size.width >= 140.0f)
{
[backButton setFrame:CGRectMake(0.0f, 0.0f, 140.0f, 30.0f)];
}
backNaviButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
Above code working fine with iOS 7 and below versions
Here are the compare screen shots
iOS 7
iOS 8
Test against string length rather than button width
UIButton* backButton = [UIButton buttonWithType:101]; // left-pointing shape!
[backButton addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
if (parent.title.length>maxStringLength) {
[backButton setTitle:[NSString stringWithFormat:@"%@...",[parent.title substringToIndex:maxStringLength]] forState:UIControlStateNormal];
} else {
[backButton setTitle:parent.title forState:UIControlStateNormal];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.