//添加返回按鈕 -(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:^{ }]; }
以上所述是小編給大家介紹的iOS中常用設置返回按鈕,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對本站網站的支持!