小编Far*_*ohi的帖子

如何删除 UIBarButtonItem 左侧的填充?

我想使用自定义视图 作为 UINavigationController 中留下的 UIBarButtonItem,是否可以删除此处的左侧填充?

我已经尝试过了:

let  btn = UIButton()
btn.frame = CGRect(x: -50, y: -50, width: 44, height: 50)
btn.setImage(UIImage(name:"img").withRenderingMode(.alwaysTemplate), for: .normal)
btn.addTarget(self, action: #selector(openSetting), for: .touchUpInside)

let leftButtonBar = UIBarButtonItem(customView: btn)

self.navigationItem.leftBarButtonItems = ( [leftButtonBar , otherBtn ])
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

如何删除剩余空间设置图标

更新。厌倦了这段代码:

let view = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 
view.backgroundColor = .gray
let  btn = UIButton()
btn.frame = CGRect(x: -15, y: 0, width: 44, height: 50)
btn.setImage(UIImage(name:"img").withRenderingMode(.alwaysTemplate), for: .normal)
btn.addTarget(self, action: #selector(DashboardTabBarController.openSetting), for: .touchUpInside) …
Run Code Online (Sandbox Code Playgroud)

uinavigationcontroller ios swift

3
推荐指数
1
解决办法
7920
查看次数

如何在 Swift 中切换可见性 GONE 和 VISIBLE

我想在可见性GONEVISIBLE. 这在Android开发中确实很容易实现,但我不知道如何在Swift中使用相同的方法

我尝试使用此代码将标签设置为消失:

// set the width constraint to 0
let widthConstraint = NSLayoutConstraint(item:  self.labelShortDescription, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 0)
self.labelShortDescription.addConstraint(widthConstraint)

// set the height constraint to 0
let heightConstraint = NSLayoutConstraint(item:  self.labelShortDescription, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 0)
self.labelShortDescription.addConstraint(heightConstraint)
Run Code Online (Sandbox Code Playgroud)

visibility ios swift

2
推荐指数
1
解决办法
6357
查看次数

标签 统计

ios ×2

swift ×2

uinavigationcontroller ×1

visibility ×1