-1

I want to customize SLComposeSheetConfigurationItem I am looking to change the font and color for its title and value There does not seem to be any documentation for this but several apps like Evernote have done that.

Kashif
  • 4,642
  • 7
  • 44
  • 97

1 Answers1

1

SLComposeSheetConfigurationItem's contents are loaded in tableView, so you can't directly access both label. You need to first get tableView by accessing hierarchy of views and then access visibleCells from table view. there are only one cell, so access subViews of contentView of first cell which will give you two label.

So, first one label is left hand side and second one at right hand side. Change its font size, color, title as we are doing in normal label and reload data.

See following code.

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

    if let slSheet = self.children.first as? UINavigationController {

        // Change color of Cancel and Post Button
        slSheet.navigationBar.tintColor = .orange

        // All contents of botton view are loaded inside table view at specific level of child view
        if let tblView = slSheet.children.first?.view.subviews.first as? UITableView,
            let firstCell = tblView.visibleCells.first
        {

            // Enumerate on subViews of contentView

            for (index, label) in firstCell.contentView.subviews.enumerated() {

                if index == 0 {

                    // Left label
                    if let lblLeft = label as? UILabel {
                        lblLeft.font = UIFont(name: "Helvetica-Bold", size: 20)
                        lblLeft.textColor = .orange
                    }

                } else {

                    // Right label
                    if let lblRight = label as? UILabel {
                        lblRight.font = UIFont(name: "Helvetica", size: 14)
                        lblRight.textColor = .green
                    }
                }
            }
            // Reload table if label not loading properly
            tblView.reloadData()
        }
    }
}

Output:

SLComposeSheetConfigurationItem Style Customisation

Sagar Chauhan
  • 5,715
  • 2
  • 22
  • 56