为什么在通过消息共享内容时文本撰写中缺少取消按钮?

时间:2017-11-09 04:57:47

标签: ios swift uiactivityviewcontroller

我使用以下代码在Swift中实现了分享按钮:

@IBAction func share(_ sender: UIBarButtonItem) {
    let textToShare = [ "Text to share" ]
    let activityViewController = UIActivityViewController(activityItems: textToShare, applicationActivities: nil)
    activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash

    self.present(activityViewController, animated: true, completion: nil)
}

一切似乎都有效但是当我通过消息分享内容时,如果我改变主意分享它,那么文本构成中的取消按钮就会丢失。 enter image description here

2 个答案:

答案 0 :(得分:2)

使用以下代码更改应用中的导航栏色调颜色:

{p} AppDelegate didFinishLaunchingWithOptions

中的

UINavigationBar.appearance().tintColor = UIColor.red

用要在按钮中设置的颜色替换红色。

答案 1 :(得分:0)

我在iOS 11上遇到了同样的问题,该解决方案对我来说虽然不是很好,但对我来说却是很好。

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[UINavigationBar appearance] setTranslucent:YES];
    [[UINavigationBar appearance] setBackgroundColor:[UIColor blackColor]];
    [[UINavigationBar appearance] setTitleTextAttributes:@{
            NSForegroundColorAttributeName: [UIColor blackColor]
    }];
}

    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        [[UINavigationBar appearance] setTranslucent:NO];
        //set your app color
        [[UINavigationBar appearance] setBackgroundColor:[UIColor APPCOLOR]];
        [[UINavigationBar appearance] setTitleTextAttributes:@{
                NSForegroundColorAttributeName: [UIColor APPCOLOR]
        }];
    }

PS:我也尝试了THIS解决方案,但不适用于我。