【发布时间】:2015-01-14 02:20:08
【问题描述】:
在 iPhone 6+ 中,leftBarButtonItem 的左侧偏移量比其他 iPhone 的多(其他 iPhone 的左侧空间大致相同)。我怎样才能得到这个空间的宽度?或者我可以为所有 iPhone 设置这个空间的宽度?
左-iphone5, 对——iphone6+
【问题讨论】:
标签: ios iphone-6-plus
在 iPhone 6+ 中,leftBarButtonItem 的左侧偏移量比其他 iPhone 的多(其他 iPhone 的左侧空间大致相同)。我怎样才能得到这个空间的宽度?或者我可以为所有 iPhone 设置这个空间的宽度?
左-iphone5, 对——iphone6+
【问题讨论】:
标签: ios iphone-6-plus
这段代码应该可以帮助您解决偏移:
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;
【讨论】: