用于iPhone的左侧空间leftBarButtonItem

时间:2015-01-14 02:20:09

标签: ios iphone-6-plus

在iPhone 6+中,leftBarButtonItem比其他iPhone更具左偏移(其他iPhone的左侧空间大致相同)。我怎样才能获得这个空间的宽度?或者也许我可以为所有iPhone设置这个空间的宽度?

左 - iphone5, 对 - iphone6 +

enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

此代码可以帮助您解决偏移问题:

UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
[leftButton sizeToFit];
[leftButton addTarget:self action:@selector(onNavLeftLabelBarButtonClicked) forControlEvents:UIControlEventTouchUpInside];

UIView* leftView = [[UIView alloc] initWithFrame:CGRectMake(x, y, 200, 44)];
//use the x and y to play around with the offset, changing it conditionally
//for Iphone 5 and 6+ for example
leftView.bounds = CGRectInset(leftView.frame, x2, y2); //play around with the insets
[leftView addSubview:self.leftButton];

UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:self.leftView];
self.navigationItem.leftBarButtonItem = leftBarButton;