简体   繁体   中英

Back button text prob with iOS 8

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM