Swift 左巴布托尼姆移除填充物?

Swift 左巴布托尼姆移除填充物?,swift,Swift,我想在UINavigationController中使用一个徽标作为LeftbarButtonItem,是否可以在此处删除左侧填充 我一直在努力: let logoView = UIView(frame: CGRectMake(-15, 0, 44, 44)) logoView.backgroundColor = UIColor.darkGrayColor() var leftBarButtonItem: UIBarButtonItem = UIBarButtonIte

我想在UINavigationController中使用一个徽标作为LeftbarButtonItem,是否可以在此处删除左侧填充

我一直在努力:

    let logoView = UIView(frame: CGRectMake(-15, 0, 44, 44))
    logoView.backgroundColor = UIColor.darkGrayColor()

    var leftBarButtonItem: UIBarButtonItem = UIBarButtonItem(customView: logoView)

    self.navigationItem.setLeftBarButtonItem(leftBarButtonItem, animated: false)
但这不起作用。我的意思是在这张图片中显示的空间:

有什么想法吗?提前谢谢

以下是Swift解决方案:

    let logoView = UIView(frame: CGRectMake(0, 0, 44, 44))
    logoView.backgroundColor = UIColor.darkGrayColor()

    let negativeSpacer = UIBarButtonItem.init(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
    negativeSpacer.width = -20;

    let leftBarButtonItem: UIBarButtonItem = UIBarButtonItem(customView: logoView)

    self.navigationItem.leftBarButtonItems = [negativeSpacer, leftBarButtonItem]

以下是移除自定义左按钮项左侧填充的示例:

UIBarButtonItem *backButtonItem // Assume this exists, filled with our custom view

// Create a negative spacer to go to the left of our custom back button, 
// and pull it right to the edge:
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] 
    initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace 
    target:nil action:nil];
negativeSpacer.width = -5; 

// Note: We use 5 above b/c that's how many pixels of padding iOS seems to add

// Add the two buttons together on the left:
self.navigationItem.leftBarButtonItems = [NSArray 
    arrayWithObjects:negativeSpacer, backButtonItem, nil];

@Piyush Sharma'答案的快速版本

actionBarWidth = self.navigationController?.navigationBar.frame.width as! CGFloat
actionBarHeight = self.navigationController?.navigationBar.frame.height as! CGFloat

actionBarView.frame = CGRect (x: 0, y: 0, width: actionBarWidth, height: actionBarHeight)

 let emptySpace = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
 emptySpace.width = -16
 let leftBarBtn = UIBarButtonItem(customView: actionBarView)
 self.navigationItem.leftBarButtonItems = [emptySpace,leftBarBtn]

我仍然会找到那个(旧的)解决方案,但它已经不起作用了。好的,现在它起作用了——谢谢。我再加上快速的解决方案。这是迄今为止唯一对我有效的方法。谢谢@erkanyildiz:你有没有找到一种方法让它在iOS 11中工作?