iOS 11 之前,如果使用系統(tǒng)自帶的返回按鈕,為了達(dá)到導(dǎo)航欄返回按鈕只顯示返回圖片,不顯示文字信息的效果,可以通過設(shè)置導(dǎo)航欄的的屬性
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)forBarMetrics:UIBarMetricsDefault];
而在iOS 11版本開始,上邊的方法就不好用了;之前開發(fā)時(shí)更多的是用自定義返回按鈕去實(shí)現(xiàn)效果.今天逛csdn時(shí),發(fā)現(xiàn)了一種思路,鏈接https://blog.csdn.net/wang_gwei/article/details/78975305 ,需要寫的代碼不多也不影響系統(tǒng)自帶的側(cè)滑返回手勢(shì)功能使用,故作筆記:
第一步:
默認(rèn)狀態(tài)下返回按鈕文字設(shè)置為透明
// 修改導(dǎo)航按鈕顏色
// [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
// 隱藏返回按鈕的文字,只保留箭頭
[[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]}forState:UIControlStateNormal];//將title 文字的顏色改為透明
第二步:
高亮狀態(tài)下返回按鈕文字也需要設(shè)置為透明,否則點(diǎn)擊按時(shí)時(shí)候會(huì)出現(xiàn)文字,就比較奇怪了
[[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]}forState:UIControlStateHighlighted]; //將title 文字的顏色改為透明