MFMailCompose Custom buttons

2019-09-18 02:01发布

        UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cancel.png"]]];
button.target = picker.navigationBar.topItem.leftBarButtonItem ;
button.action = picker.navigationBar.topItem.leftBarButtonItem.action;
picker.navigationBar.topItem.leftBarButtonItem=button;

Hi folks, I'm trying to change the style of the buttons of the mail composer. The above code does change the look of the button, however the action seems to be lost. Any ideas how I can overcome this? Thanks.

1条回答
够拽才男人
2楼-- · 2019-09-18 02:54

The fix for this is fairly simple. You add a method to this button and then define what should happen in the method. So first, put this line after you declare your button.

[button addTarget:self action:@selector(aButtonClicked:) forControlEvents:UIControlEventTouchUpInside];

That will add a method to be called when the button is clicked/touched. Then, later in the code, you create the actual method that the button will be calling.

-(void)aButtonClicked:(id)sendr{
//Do stuff here

}

Hope this helped :)

查看更多
登录 后发表回答