[英]Back button text prob with iOS 8
以下是用于后退按钮文本的代码
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];
上面的代码可以在iOS 7及以下版本上正常工作
这是比较屏幕截图
IOS 7
iOS 8
测试字符串长度而不是按钮宽度
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];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.