我成功地通过给定代码更改了右导航按钮 的文本。但我也想改变它有一个 delfault background 。
我只想显示透明背景的文本。
我也试过
UIBarButtonItem *rightBtn=[[UIBarButtonItem alloc] initWithTitle:@"MyTitle" style:UIBarButtonItemStyleDone target:self action:@selector(myMethod)];
rightBtn.tintColor =[UIColor clearColor];
但仍然显示按钮背景。
有没有办法通过改变任何没有背景的不同风格来实现它。或者是否有其他简单的方法可以将按钮更改为没有透明背景的文本。
最佳答案
你可以使用这个:
UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
btn.backgroundColor=[UIColor clearColor];
[btn setTitle:@"Title" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(myMethod) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightBtn=[[UIBarButtonItem alloc] initWithCustomView:btn];
[self.navigationItem setRightBarButtonItem:rightBtn];
关于ios - 更改导航右键的背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25760146/