左 space 的 leftBarButtonItem 用于 iPhone 的
Left space leftBarButtonItem for iPhone's
在 iPhone 6+ leftBarButtonItem 中,左偏移量比其他 iPhone 多(其他 iPhone 的左偏移量大致相同 space)。我怎样才能得到这个 space 的宽度?或者我可以为所有 iPhone 的 space 设置宽度?
左 - iphone5,
右 - iphone6+
此代码应该可以帮助您使用偏移量:
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;
在 iPhone 6+ leftBarButtonItem 中,左偏移量比其他 iPhone 多(其他 iPhone 的左偏移量大致相同 space)。我怎样才能得到这个 space 的宽度?或者我可以为所有 iPhone 的 space 设置宽度?
左 - iphone5, 右 - iphone6+
此代码应该可以帮助您使用偏移量:
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;