How to prevent side area clickable of UIBarButtonItem?

烈酒焚心 提交于 2020-01-24 12:15:47

问题


`

Whenever i click on this area , action also perform on this.


回答1:


Don't worry about this behavior, iOS auto tapp near element if there is not other element.

If you really want to prevent to click except button, then you have to put Element on unused area which should be inherited from UIControl or able to get UserInteraction.




回答2:


I got solution. I put one UIButton between these two UIBarButtonItem and make it custom and nil it's selector.




回答3:


Also, you can try this: (Swift version)

    let btnName = UIButton()
    btnName.setImage(UIImage(named: "settings_filled_25"), forState: .Normal)
    btnName.frame = CGRectMake(0, 0, 30, 30)
    btnName.addTarget(self, action: Selector("toggleRight"), forControlEvents: .TouchUpInside)

    var rightView = UIView()
    rightView.frame = CGRectMake(0, 0, 30, 30)
    rightView.addSubview(btnName)

    let rightBarButton = UIBarButtonItem()
    rightBarButton.customView = rightView
    self.navigationItem.rightBarButtonItem = rightBarButton


来源:https://stackoverflow.com/questions/11716313/how-to-prevent-side-area-clickable-of-uibarbuttonitem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!