创建具有固定大小和自定义图标的UIBarButtonItem

时间:2018-05-07 09:35:29

标签: ios uibarbuttonitem

我已经创建了如下图所示的导航栏

enter image description here

" drop" button是一个自定义系统UIBarButtonItem。它包含在右栏按钮项中,其区域已扩展。

我希望它的大小适合我设置的图像,例如右侧的“撰写”按钮。

1 个答案:

答案 0 :(得分:0)

public func setCustomButton() {

    let btnSearch: UIButton = UIButton(type: .custom)
    btnSearch.frame = CGRect(x: 0, y: 0, width: 25.0, height: 25.0)
    btnSearch.setImage("Your image", for: .normal)
    btnSearch.addTarget(self, action: #selector(yourActionName(_:)), for: .touchUpInside)
    et btnBarButtonSearch: UIBarButtonItem = UIBarButtonItem(customView: btnSearch)
    navigationItem.rightBarButtonItems = [btnBarButtonSearch]
 }
希望,它会帮助你。

相关问题