iOS开发 自定义导航栏按钮

来源:互联网 发布:苹果电脑win7换mac 编辑:程序博客网 时间:2024/05/21 09:06

第一种 使用系统提供的方法,具体直接看代码

self.navigationItem.leftBarButtonItem=[[UIBarButtonItemalloc] initWithTitle:@"取消"style:UIBarButtonItemStylePlaintarget:selfaction:@selector(cancleAction)];

    //自定义保存按钮

    self.navigationItem.rightBarButtonItem=[[UIBarButtonItemalloc] initWithTitle:@"保存"style:UIBarButtonItemStyleDonetarget:selfaction:@selector(submitAction)];

第二种 使用自定义控件的方式

UIButton *btu=[UIButton buttonWithType:UIButtonTypeCustom];

//    [btu setTitle:@"取消" forState:UIControlStateNormal];

//    [btu setTintColor:[UIColor whiteColor]];

//    btu.titleLabel.font=[UIFont systemFontOfSize:15.0];

//    [btu addTarget:self action:@selector(cancleAction) forControlEvents:UIControlEventTouchUpInside];

//    //自定义返回按钮

//    UIBarButtonItem *backBtu=[[UIBarButtonItem alloc] initWithCustomView:btu];

//    self.navigationItem.leftBarButtonItems=@[backBtu];


0 0