简体   繁体   English

更改SLComposeSheetConfigurationItem的色调/文本颜色

[英]Changing SLComposeSheetConfigurationItem's tint color/text color

So for the last two weeks I have been working on my GitHub repo https://github.com/satheeshwaran/iOS-8-Features-Demo where in I tried to demo the Share extension introduced in iOS 8. I got to know the way in which I could add SLComposeSheetConfigurationItem to a SLComposeServiceViewController but I was not able to figure out how to change the tint color or the text color of a SLComposeSheetConfigurationItem . 因此,在过去的两周里,我一直致力于我的GitHub回购https://github.com/satheeshwaran/iOS-8-Features-Demo我试图演示iOS 8中引入的Share扩展。我知道了我可以将SLComposeSheetConfigurationItem添加到SLComposeServiceViewController但我无法弄清楚如何更改SLComposeSheetConfigurationItem的色调颜色或文本颜色。

What I have did so far, 到目前为止我做了什么,

在此输入图像描述

See in the above figure I would like to set the description and the My First Share to some color of my choice, also may be I would like to customize the font or something. 在上图中看到我想将描述和My First Share设置为我选择的某种颜色,也可能是我想自定义字体或其他东西。 I dug into the SocialFramework a bit but was not able to get anything out of it. 我挖了一下SocialFramework但是却无法从中得到任何东西。

I saw Evernote's share extension on my iPad and it looks like this, 我在iPad上看到了Evernote的分享扩展,它看起来像这样, 在此输入图像描述

If you see at the bottom there is an icon and also the text color etc matches the theme of the navigation bar. 如果你看到底部有一个图标,文字颜色等也与导航栏的主题相匹配。

Quoting the WWDC 2014 presentation on extension programming, 引用WWDC 2014关于扩展编程的演示,

SLComposeServiceViewController for standard UI 用于标准UI的SLComposeServiceViewController
UI/ NSViewController for custom UI Coming to my question, 用于自定义UI的UI / NSViewController来到我的问题,

  1. Can I customize SLComposeServiceViewController and SLComposeSheetConfigurationItem to look like this?? 我可以自定义SLComposeServiceViewControllerSLComposeSheetConfigurationItem看起来像这样?
  2. The second question is about the quote, can the default SLComposeServiceViewController be customized at all?? 第二个问题是关于引用, SLComposeServiceViewController可以自定义默认的SLComposeServiceViewController or should I go with a UIViewController subclass to do my own UI. 或者我应该使用UIViewController子类来创建自己的UI。
  3. How would have Evernote done it custom UIViewController subclass to duplicate the behavior or using SLComposeServiceViewController ( I am not sure whether to ask this but I want answers) 如何让Evernote自定义UIViewController子类来复制行为或使用SLComposeServiceViewController (我不确定是否要问这个,但我想要答案)

For customizing the navigation bar. 用于自定义导航栏。 The normal, non-dot notation methods work fine for me. 正常的非点符号方法对我来说很好。

[[[self navigationController] navigationBar] setTintColor:[UIColor whiteColor]];
[[[self navigationController] navigationBar] setBackgroundColor:[UIColor redColor]];
[[self navigationItem] setTitleView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"elephant.png"]]];

For the SLComposeSheetConfigurationItem that does look like a custom subclass given the icon. 对于SLComposeSheetConfigurationItem ,它看起来像给定图标的自定义子类。

The only public methods for configuration on SLComposeSheetConfigurationItem @property (nonatomic, copy) NSString *title; // The displayed name of the option. @property (nonatomic, copy) NSString *value; // The current value/setting of the option. @property (nonatomic, assign) BOOL valuePending; // Default is NO. set to YES to show a progress indicator. Can be used with a value too. SLComposeSheetConfigurationItem @property (nonatomic, copy) NSString *title; // The displayed name of the option. @property (nonatomic, copy) NSString *value; // The current value/setting of the option. @property (nonatomic, assign) BOOL valuePending; // Default is NO. set to YES to show a progress indicator. Can be used with a value too.上配置的唯一公共方法@property (nonatomic, copy) NSString *title; // The displayed name of the option. @property (nonatomic, copy) NSString *value; // The current value/setting of the option. @property (nonatomic, assign) BOOL valuePending; // Default is NO. set to YES to show a progress indicator. Can be used with a value too. @property (nonatomic, copy) NSString *title; // The displayed name of the option. @property (nonatomic, copy) NSString *value; // The current value/setting of the option. @property (nonatomic, assign) BOOL valuePending; // Default is NO. set to YES to show a progress indicator. Can be used with a value too.

My code, which i've used to get result similar to Evernote: 我的代码,我曾经得到的结果类似于Evernote:

func getTopWithColor(color: UIColor, size: CGSize) -> UIImage {
    let rect = CGRectMake(0, 0, size.width, size.height)
    UIGraphicsBeginImageContextWithOptions(size, false, 0)
    color.setFill()
    UIRectFill(rect)
    if let img = UIImage(named: "icon.png") {
        img.drawInRect(CGRectMake((size.width-size.height)/2, 0, size.height, size.height))
    }
    let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    return image
}

override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationController?.navigationBar.tintColor = UIColor.blackColor()
    let navSize = self.navigationController?.navigationBar.frame.size
    self.navigationController?.navigationBar.setBackgroundImage(getTopWithColor(UIColor.whiteColor(), size: navSize!), forBarMetrics: .Default)
}

带有自定义导航栏的SLComposeServiceViewController

实际上SLComposeServiceViewController的导航控制器是一个SLSheetNavigationController,设置标题视图到它的导航栏似乎没有任何效果,也是标题文本属性。

I think proper answer here: 我认为这里有正确答案:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    if let table = textView.superview?.superview?.superview as? UITableView {
        let length = table.numberOfRows(inSection: 0)
        table.scrollToRow(at: IndexPath(row: length - 1, section: 0), at: .bottom, animated: true)

        if let row = table.cellForRow(at: IndexPath(item: 0, section: 0)) as? UITableViewCell {
            row.textLabel?.textColor = UIColor.green
        }
    }
}

SLComposeSheetConfigurationItem just rendered in UITableViewCell which you can modify. SLComposeSheetConfigurationItem刚刚在UITableViewCell中呈现,您可以修改它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM