【问题标题】:Left space leftBarButtonItem for iPhone'siPhone 的左侧空格 leftBarButtonItem
【发布时间】:2015-01-14 02:20:08
【问题描述】:

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

左-iphone5, 对——iphone6+

【问题讨论】:

    标签: ios iphone-6-plus


    【解决方案1】:

    这段代码应该可以帮助您解决偏移:

    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 并设置值吗?
    • @Nikita - 好吧,正如您所指出的,您观察到的唯一区别是 Iphone 5/6 和 6+ 之间。因此,您可以做的只是检查 if (6+) {then x = ...) else {x = ...}
    猜你喜欢
    • 2011-09-10
    • 2018-04-03
    • 1970-01-01
    • 2015-12-11
    • 2015-05-02
    • 2014-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多