Ios name extension message header

I want to change the name of the mail buttons in the SLComposeServiceViewController. I managed to get UIButton:

NSArray* subviews =[self.navigationController.navigationBar subviews]; UIButton* postButton =[subviews lastObject]; 

and I tried to set the header as follows:

 [postButton setTitle:@"Save" forState:UIControlStateNormal]; 

but the name has not changed.

Can anyone help me with this?

I saw the Evernote extension on my iPad and it looks like this: enter image description here

UPDATE

My decision:

I found a solution for my question, I deleted the original navigation bar and created a custom navigation bar.

I have two navigation panels: 1. with the buttons "cancel" \ "save" 2. with the button "back"

and I change them when navigating to another viewing manager (in my case, I needed to upload a file, and the user needed to select a location from the list)

NOTE. If you do not implement configurationItems , you only need the first navigation bar. (just call to install custom navigation bar from viewDidAppear

So my code is here:

 @property (strong, nonatomic) UINavigationBar *customNavBar; -(void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; self.customNavBar = [[UINavigationBar alloc] initWithFrame:self.navigationController.navigationBar.bounds]; [self.navigationController.navigationBar removeFromSuperview]; [self.navigationController.view addSubview:self.customNavBar]; [self setCancelSaveNavigationItem]; } 

setCancelSaveNavigationItem -> called from viewDidAppear shareViewController

 -(void)setCancelSaveNavigationItem { UINavigationItem *newItem = [[UINavigationItem alloc] init]; UIBarButtonItem *cancelBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Cancel",nil) style:UIBarButtonItemStylePlain target:self action:@selector(cancelButtonTapped:)]; UIBarButtonItem *saveBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done",nil) style:UIBarButtonItemStyleDone target:self action:@selector(saveButtonTapped:)]; newItem.leftBarButtonItem = cancelBarButtonItem; newItem.rightBarButtonItem = saveBarButtonItem; [self.customNavBar setItems:@[newItem]]; [self.navigationItem setBackBarButtonItem:cancelBarButtonItem]; [self.navigationItem setRightBarButtonItem:saveBarButtonItem]; if(self.item.value == nil){ saveBarButtonItem.enabled = NO; } } 

setBackNavigationItem -> called in configurationItems in self.item.tapHandler function

 -(void)setBackNavigationItem { UINavigationItem *newItem = [[UINavigationItem alloc] init]; UIBarButtonItem *selectBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Select",nil) style:UIBarButtonItemStylePlain target:self action:@selector(selectButtonTapped:)]; UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:[NSString stringWithFormat:@"❮ %@", NSLocalizedString(@"Back",nil)] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonTapped:)]; newItem.leftBarButtonItem = backBarButtonItem; newItem.rightBarButtonItem = selectBarButtonItem; [self.customNavBar setItems:@[newItem]]; [self.navigationItem setBackBarButtonItem:backBarButtonItem]; [self.navigationItem setRightBarButtonItem:selectBarButtonItem]; } 

Manual Buttons:

 - (void)backButtonTapped:(id)sender { if([self.navigationController.viewControllers count] ==2){ [self setCancelSaveNavigationItem]; } [self.navigationController popViewControllerAnimated:YES]; } - (void)cancelButtonTapped:(id)sender { [self cancel]; } - (void)selectButtonTapped:(id)sender { ... [self setCancelSaveNavigationItem]; [self popConfigurationViewController]; } - (void)saveButtonTapped:(id)sender { ... [self cancel]; } 

And it works for me !!!

Result:

enter image description here

enter image description here

+5
source share
2 answers

Your code:

 NSArray* subviews =[self.navigationController.navigationBar subviews]; UIButton* postButton =[subviews lastObject]; 

... this is a really bad idea . It only works because the message button is in subviews and is the last element of the array. But the contents of subviews undocumented and may change at any time. In addition, since there is no public API for this button, it is possible that there is a framework code for preventing or overriding changes to the button text, so even if we assume that you have the correct user interface element, you still cannot change it.

The Evernote user interface is almost certainly a complete user design that only resembles the SLComposeServiceViewController . Share extensions are not required to use the SLComposeServiceViewController , which is just for convenience. If this does not fit your needs, create your own.

Update: out of curiosity, I unzipped the Evernote IP address and looked at EvernoteShare.appex on nm . There is no reference to the SLComposeServiceViewController which confirms that Evernote does not use this class in its extension.

+7
source

Just in viewDidAppear

 self.navigationController?.navigationBar.topItem?.rightBarButtonItem?.title = "Save" 
+5
source

Source: https://habr.com/ru/post/1213243/


All Articles