我正在尝试将我的backButton设置为一个简单的"<"像这样:
self.navigationItem.backBarButtonItem = UIBarButtonItem(title:"", style:.Plain, target:nil, action:nil)
print(self.navigationItem.backBarButtonItem?.title)
打印将显示"",但在模拟器上运行我的应用程序将始终显示上一个VC的标题。
虽然我测试了
navigationController?.navigationBar.tintColor = UIColor(red:0.60, green:0.60, blue:0.60, alpha:1.0)
将更改按钮的颜色。
注意:
我正在UIViewController
嵌入UINavigationController
只需UIViewController
答案 0 :(得分:1)
您需要在整个应用中隐藏UIBarButtonItem.appearance().setTitlePositionAdjustment(UIOffsetMake(0, -100), forBarMetrics: UIBarMetrics.Default)
标题,对吗?
然后这个技巧可以帮助你实现这一目标。
<强>夫特:强>
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -100)
forBarMetrics:UIBarMetricsDefault];
目标C:
appdelegate
在didFinishLaunchingWithOptions
public void addListenerOnButton() {
imageButton = (ImageButton) findViewById(R.id.imageButton1);
imageButton.setOnClickListener(new OnClickListener() {
int i=0;
@Override
public void onClick(View arg0) {
i+=1;
//Move position
Random r = new Random();
int buttonHeight;
int buttonWidth;
int xPos = r.nextInt(480);
int yPos = r.nextInt(800);
imageButton.setX(xPos);
imageButton.setY(yPos);
//Change image
int[] imageIds = {
R.drawable.pic1,
R.drawable.pic2,
R.drawable.pic3,
R.drawable.pic4,
R.drawable.pic5,
R.drawable.pic6,
R.drawable.pic7,
R.drawable.pic8,
R.drawable.pic9,
R.drawable.pic10
};
int randomImageId = imageIds[r.nextInt(imageIds.length)];
imageButton.setImageResource(randomImageId);
if(i==5){
Toast offMsg = Toast.makeText(getBaseContext(),
"This is the fifth button press", Toast.LENGTH_SHORT);
offMsg.show();
int i=0;
}
}
});
}
中添加上述代码,我们将标题推出框架(隐藏):p。
<强>结果:强>
答案 1 :(得分:0)
self.navigationItem.backBarButtonItem = UIBarButtonItem(title:"<", style:.Plain, target:nil, action:nil)
答案 2 :(得分:0)
在目标c中使用以下代码推送控制器:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@" " style:UIBarButtonItemStylePlain target:nil action:nil];
[self.navigationItem setBackBarButtonItem:backButton];
self.navigationController.navigationBar.backIndicatorImage = [UIImage imageNamed:ARROW_BACK_ICON];
不要使用&#34;&#34;使用后退按钮的标题&#34; &#34;后退标题。
答案 3 :(得分:0)
试试这个
选择您的Main.storyboard - &gt;点击Hide Document Outline
- &gt;选择UIViewController
- &gt; Select Navigation Item
- &gt;选择Show the attributes inspector
- &gt;带有一个空格的后退按钮文本字段Back button = " "
OR
<强> EDITED 强>
let item = UIBarButtonItem(title: " ", style: .Plain, target: nil, action: nil)
viewController.navigationItem.backBarButtonItem = item
希望这会有所帮助。