I want to change the title of post buttons in SLComposeServiceViewController. I managed to get the UIButton:
NSArray* subviews =[self.navigationController.navigationBar subviews];
UIButton* postButton =[subviews lastObject];
and i tried to set title like this:
[postButton setTitle:@"Save" forState:UIControlStateNormal];
but the title not changed.
Can anyone help me with this?
I saw Evernote's share extension on my iPad and it looks like this:
UPDATE
My Solution:
I found solution for my question,I removed the original navigation bar and create custom nav bar.
I have two nav bar: 1. with "cancel"\"save" buttons 2. with "back" button
and I change them when navigate to other viewcontroller (in my case I needed to upload file and user need select location from list)
NOTE: if you not implement configurationItems
you need only the first nav bar. (just call to set custom nav 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 of 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];
}
Handle buttons tapped:
- (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's work for me!!!
The result: