欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

iOS中常用设置返回按钮

程序员文章站 2023-12-21 19:04:34
//添加返回按钮 -(void)backbtn{ uibutton *backbtn=[[uibutton alloc]initwithframe:cg...

//添加返回按钮
-(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中常用设置返回按钮,希望对大家有所帮助

上一篇:

下一篇: