iOS中常用设置返回按钮

时间:2022-02-15 23:27:17
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//添加返回按钮
-(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中常用设置返回按钮,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!

原文链接:http://blog.csdn.net/u011146511/article/details/53761325