【问题标题】:Changing SLComposeSheetConfigurationItem's tint color/text color更改 SLComposeSheetConfigurationItem 的色调/文本颜色
【发布时间】:2014-09-24 11:16:55
【问题描述】:

所以在过去的两周里,我一直在研究我的 GitHub 存储库 https://github.com/satheeshwaran/iOS-8-Features-Demo,在那里我尝试演示 iOS 8 中引入的 Share 扩展。我知道了如何将 SLComposeSheetConfigurationItem 添加到SLComposeServiceViewController 但我不知道如何更改 SLComposeSheetConfigurationItem 的色调或文本颜色。

到目前为止我做了什么,

见上图我想将描述和我的第一个分享设置为我选择的一些颜色,也可能是我想自定义字体之类的。我对 SocialFramework 进行了一些研究,但无法从中得到任何东西。

我在我的 iPad 上看到了 Evernote 的共享扩展,它看起来像这样,

如果您在底部看到一个图标,并且文本颜色等与导航栏的主题相匹配。

引用 WWDC 2014 关于扩展编程的演示文稿,

SLComposeServiceViewController 用于标准 UI
UI/NSViewController 用于自定义 UI 来回答我的问题,

  1. 我可以将SLComposeServiceViewControllerSLComposeSheetConfigurationItem 自定义成这样吗??
  2. 第二个问题是关于报价的,可以自定义默认的SLComposeServiceViewController吗??还是我应该使用 UIViewController 子类来做我自己的 UI。
  3. Evernote 将如何自定义 UIViewController 子类来复制行为或使用 SLComposeServiceViewController(我不确定是否要问这个问题,但我想要答案)

【问题讨论】:

    标签: ios ios8 ios8-share-extension ios8-extension


    【解决方案1】:

    用于自定义导航栏。 正常的非点符号方法对我来说很好用。

    [[[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; // 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.

    【讨论】:

      【解决方案2】:

      我的代码,我用它来获得类似于 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)
      }
      

      【讨论】:

      • 太棒了!对导航栏上的印象笔记标志有点图标设置有什么想法吗?
      • @satheeshwaran 在导航栏上添加了缺少的图标,希望对您有所帮助。
      【解决方案3】:

      其实SLComposeServiceViewController的导航控制器是一个SLSheetNavigationController,给它的导航栏设置title view好像没有任何作用,还有title text属性。

      【讨论】:

      • 是的,SLShettNaviagtionController 的行为也不像普通的 UINavigationController。
      【解决方案4】:

      我认为这里的正确答案:

      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 中,您可以对其进行修改。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多