前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >调用 MFMessageComposeViewController UINavigationBar 高出一截

调用 MFMessageComposeViewController UINavigationBar 高出一截

作者头像
GuangdongQi
发布2018-05-24 17:48:18
5610
发布2018-05-24 17:48:18
举报
文章被收录于专栏:Guangdong Qi

项目告一段落,总结一下项目中遇到的坑

使用 MFMessageComposeViewController 在程序内部发送短信,代码很简单

代码语言:javascript
复制
MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init];
controller.recipients = @[收件人手机号码1,收件人手机号码2,收件人手机号码3];
controller.body = 短信内容

controller.messageComposeDelegate = self;

[self presentViewController:controller animated:YES completion:nil];

然后是代理回调

代码语言:javascript
复制
#pragma mark ---- 发短信代理
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    [self dismissViewControllerAnimated:YES completion:nil];
    switch (result) {
        case MessageComposeResultSent:
            //信息传送成功
        {
            break;
        }
        case MessageComposeResultFailed:
            //信息传送失败
            
            break;
        case MessageComposeResultCancelled:
            //信息被用户取消传送
            
            break;
        default:
            break;
    }
}

但是当我全局设置 NavigationBar 的时候会影响 MFMessageComposeViewController 的 NavigationBar 全局设置 NavigationBar 错误代码如下:

代码语言:javascript
复制
//NavigationBar 背景颜色
[[UINavigationBar appearance]setBarTintColor:NaviBarTintColor];


[[UINavigationBar appearance] setBackgroundImage:[UIImage imageWithColor:NaviBarTintColor] forBarMetrics:UIBarMetricsDefault];

[[UINavigationBar appearance] setShadowImage:[UIImage new]];

//NavigationBar 文字属性
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:WhiteColor}];

修改方法给NavigationViewController 抽出一个基类 在 viewDidLoad 全局修改NavigationBar 如下

代码语言:javascript
复制
[self.navigationBar setTintColor:WhiteColor];

[self.navigationBar setBackgroundImage:[UIImage imageWithColor:NaviBarTintColor] forBarMetrics:UIBarMetricsDefault];

[self.navigationBar setShadowImage:[UIImage new]];

[self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:WhiteColor}];

之后会发现 MFMessageComposeViewController 的NavigationBar 是系统主题的,可以修改为自己的主题,在创建的时候加入

代码语言:javascript
复制
MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init];
controller.recipients = @[telphone];
controller.body = self.friendProfitModel.inviteBuyDebtSmsContent;
controller.navigationBar.tintColor = WHColorBlack;

controller.messageComposeDelegate = self;

[self presentViewController:controller animated:YES completion:nil];

UIBarButtonItem *bar=    [[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonItemAction)];


[[[[controller viewControllers] lastObject] navigationItem] setRightBarButtonItem:bar];

[[[[controller viewControllers] lastObject] navigationItem] setTitle:@"邀请好友"];

代理回调不变

好本坑完美解决

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017.05.05 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 项目告一段落,总结一下项目中遇到的坑
相关产品与服务
短信
腾讯云短信(Short Message Service,SMS)可为广大企业级用户提供稳定可靠,安全合规的短信触达服务。用户可快速接入,调用 API / SDK 或者通过控制台即可发送,支持发送验证码、通知类短信和营销短信。国内验证短信秒级触达,99%到达率;国际/港澳台短信覆盖全球200+国家/地区,全球多服务站点,稳定可靠。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档