Method One: Set the text style of Barbuttonitem to Transparent color, the code is as follows:
[[Uibarbuttonitem appearance] Settitletextattributes:@{nsforegroundcolorattributename: [UIColor ClearColor]} Forstate:uicontrolstatenormal]; [[Uibarbuttonitem appearance] Settitletextattributes:@{nsforegroundcolorattributename: [UIColor ClearColor]} Forstate:uicontrolstatehighlighted];
In addition, this method causes the title to not be centered and is shifted a lot, as shown below (although not displayed, it also occupies a large portion of the left side of the navigation bar)
Method Two: Add a category to Uiviewcontroller, and then replace the interchange Viewdidappear with the method swzilling in the Load method, some of the code is as follows
+ (void) load {Swizzlemethod ([self class], @selector (viewdidappear:), @selector (Ac_viewdidappear));} -(void) ac_viewdidappear{self.navigationItem.backBarButtonItem = [[Uibarbuttonitem alloc] initwithtitle:@ "" Style:uibarbuttonitemstyleplain Target:self Action:nil]; [Self ac_viewdidappear];} void Swizzlemethod (class class, Sel originalselector, sel swizzledselector) {//The method might not exist in the class , but in its superclass Method Originalmethod = Class_getinstancemethod (class, Originalselector); Method Swizzledmethod = Class_getinstancemethod (class, Swizzledselector); Class_addmethod would fail if original method already exists BOOL Didaddmethod = Class_addmethod (class, Originalselec Tor, Method_getimplementation (Swizzledmethod), method_gettypeencoding (Swizzledmethod)); The method doesn ' t exist and we just added one if (didaddmethod) {Class_replacemethod (class, Swizzledsele ctor, Method_getimplementation (Originalmethod), method_gettypeencoding (Originalmethod)); } else {method_exchangeimplementations (Originalmethod, Swizzledmethod); }}
Precautions:
- To assign a value to the entire Backbuttonitem can,?? This method does not work, because backbarbuttonitem default is empty, to nil method message, the default declaration is not executed (refer to the official website)
@" ";
- Leftbarbuttonitem and Backbarbuttonitem display relationship: Leftbarbuttonitem is the first to display the current VC Leftbarbuttonitem, No show the last VC Backbarbuttonitem, no show the title of the last VC (refer to the official website or the official website explained clearly)
IOS 11 Using method swizzling, remove the text from the navigation bar back button