Satheesh
Satheesh

Reputation: 11276

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.

What I have did so far,

enter image description here

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. I dug into the SocialFramework a bit but was not able to get anything out of it.

I saw Evernote's share extension on my iPad and it looks like this, enter image description here

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,

SLComposeServiceViewController for standard UI
UI/NSViewController for custom UI Coming to my question,

  1. Can I customize SLComposeServiceViewController and SLComposeSheetConfigurationItem to look like this??
  2. The second question is about the quote, can the default SLComposeServiceViewController be customized at all?? or should I go with a UIViewController subclass to do my own 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)

Upvotes: 4

Views: 3630

Answers (4)

fluder
fluder

Reputation: 579

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.

Upvotes: 0

Tom Baranowicz
Tom Baranowicz

Reputation: 111

My code, which i've used to get result similar to 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

Upvotes: 4

Jason
Jason

Reputation: 814

Actually the navigation controller of SLComposeServiceViewController is a SLSheetNavigationController, setting title view to its navigation bar seems doesn't have any effects, also the title text attribute.

Upvotes: 1

m00sey
m00sey

Reputation: 689

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.

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.

Upvotes: 6

Related Questions