Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 907
Gison George Avatar asked Jul 21 '16 05:07

Gison George


2 Answers

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);
   }
}
like image 196
Moxarth Avatar answered Oct 20 '22 00:10

Moxarth


I know the original post mentions using objective-c but in the event anyone needs the swift answer, here it is

override func viewDidLoad()
{
    super.viewDidLoad()
    self.extensionContext?.widgetLargestAvailableDisplayMode = .compact
}

When set to compact, the app will only support compact mode i.e. show less/show show buttons/functionality will be gone.

here's some documentation for more info

like image 33
CharlieNorris Avatar answered Oct 20 '22 00:10

CharlieNorris