自定义NavgationBar返回按钮(Swift & OC)

前端之家收集整理的这篇文章主要介绍了自定义NavgationBar返回按钮(Swift & OC)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Objective-C

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0,40,40);
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    [btn setTitle:@"返回" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];


Swift 版本

func createRightBarButtonItem()
    {
        buttonRight = UIButton.init(type: UIButtonType.Custom)
        buttonRight.frame = CGRectMake(0,40)
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: buttonRight)
        buttonRight.setTitle("Edit",forState: UIControlState.Normal)
        buttonRight.addTarget(self,action: Selector("jion:"),forControlEvents: UIControlEvents.TouchUpInside)
        
    }
原文链接:https://www.f2er.com/swift/325239.html

猜你在找的Swift相关文章