改变SLComposeSheetConfigurationItem的色调颜色/文本颜色

4
在过去两周中,我一直在使用GitHub repo https://github.com/satheeshwaran/iOS-8-Features-Demo 进行工作,试图演示iOS 8中引入的共享扩展功能。我了解到如何将SLComposeSheetConfigurationItem添加到SLComposeServiceViewController中,但我无法弄清楚如何更改SLComposeSheetConfigurationItem的色调或文本颜色。

到目前为止,我已经做了什么,

enter image description here

请看上图,我想将说明和"My First Share"设置为自己选择的颜色,并且可能还要自定义字体等。我深入研究了SocialFramework,但是没有找到任何有用信息。

我看到iPad上的Evernote共享扩展如下:

enter image description here

如果您看底部,可以发现其图标以及文本颜色等都与导航栏的主题相匹配。

引用WWDC 2014有关扩展编程的演示,

SLComposeServiceViewController用于标准UI
自定义UI使用UI / NSViewController 关于我的问题,

  1. 我可以自定义SLComposeServiceViewControllerSLComposeSheetConfigurationItem以看起来像这样吗?
  2. 第二个问题是关于引述的,是否可以完全自定义默认的SLComposeServiceViewController?还是应该使用UIViewController子类来进行自己的UI设计。
  3. Evernote如何使用自定义UIViewController子类来复制其行为,还是使用SLComposeServiceViewController?(我不确定是否要问这个问题,但我想得到答案)
4个回答

6

对于自定义导航栏。一般的、非点符号表示法方法对我来说很好用。

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

对于 SLComposeSheetConfigurationItem,根据图标来看,它似乎是一个自定义的子类。 SLComposeSheetConfigurationItem 的唯一公共配置方法有: @property (nonatomic, copy) NSString *title; // 选项的显示名称。 @property (nonatomic, copy) NSString *value; // 选项的当前值或设置。 @property (nonatomic, assign) BOOL valuePending; // 默认为NO。设置为 YES 以显示进度指示器。也可以与值一起使用。

4

我编写的代码类似于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 with custom navigation bar


太好了!有没有关于在导航栏上设置Evernote标志图标的想法? - Satheesh
@satheeshwaran 在导航栏上添加了缺失的图标,希望能有所帮助。 - Tom Baranowicz

1
实际上,SLComposeServiceViewController的导航控制器是SLSheetNavigationController,将标题视图设置到其导航栏似乎没有任何效果,也不会影响标题文本属性。

是的,SLShettNaviagtionController 也不像普通的 UINavigationController 那样运作。 - Satheesh

0

我认为这里的正确答案是:

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 只是在 UITableViewCell 中呈现,您可以进行修改。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接