Search code examples
iosobjective-cwidgettoday-extension

Hide "Show More" button from Today widget in iOS10


I am building an iOS Today widget, and while testing for iOS 10, I see a "Show More" / "Show Less" button on the top right of the widget header. How can I remove this button? I am using Objective-C.


Solution

  • In iOS 10, as far as I know, the show more option is new and we cannot remove it, but we can modify it as needed.

    The following code will allow you to automatically size the Today widget. Just change the table or collection view or whatever you used in your project.

    static CGFloat padding = 25.0;
    
    - (void)viewDidLoad 
    {
        [super viewDidLoad];
    
        // Do any additional setup after loading the view from its nib.
    
        // This will remove extra separators from tableview
        self.articleTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    
        // Add the iOS 10 Show More ability
        [self.extensionContext setWidgetLargestAvailableDisplayMode:NCWidgetDisplayModeExpanded];
    }
    
    - (void)widgetActiveDisplayModeDidChange:(NCWidgetDisplayMode)activeDisplayMode withMaximumSize:(CGSize)maxSize {
       if (activeDisplayMode == NCWidgetDisplayModeCompact){
           // Changed to compact mode
           self.preferredContentSize = maxSize;
       }
       else{
           // Changed to expanded mode
           self.preferredContentSize = CGSizeMake(self.articleTableView.contentSize.width, self.articleTableView.contentSize.height + padding);
       }
    }