时间:2021-01-03 15:35:42 | 栏目:iOS代码 | 点击:次
//添加返回按钮 -(void)backBtn{ UIButton *backBtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 10, 60, 20)]; [backBtn setTitle:@"返回" forState:UIControlStateNormal]; backBtn.titleLabel.font=[UIFont systemFontOfSize:12]; backBtn.imageEdgeInsets=UIEdgeInsetsMake(2,2,2,2); [backBtn setImage:[UIImage imageNamed:@"fanhui"] forState:UIControlStateNormal]; [backBtn addTarget:self action:@selector(backto) forControlEvents:UIControlEventTouchDown]; UIBarButtonItem *leftBtn=[[UIBarButtonItem alloc]initWithCustomView:backBtn]; UIBarButtonItem *flexBtn=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; flexBtn.width=-10;//正数往左移,负数往右移 self.navigationItem.leftBarButtonItems=@[flexBtn,leftBtn]; } //返回按钮 -(void)backto{ [self dismissViewControllerAnimated:YES completion:^{ }]; }