我想在UINavigationController中使用一个标识作为LeftbarButtonItem,是否可以删除左边的填充?
不幸的是,我试过:
let logoView = UIView(frame: CGRectMake(-15,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,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];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。