0

I'm working on an application that uses today's widget where I need to show some table view with nearly 50 rows.but the screen fits only for 10 rows.So I need to increase the height of widget as per my table height.I've done a lot of research on this which says me can't be done.I've seen the yahoo stocks app,which has "show all" feature to display all stocks on widget with height more than that of screen height.If something is done somewhere why can't I do that? I've tried to set the height of my todayviewcontroller view height in both the ways using autolayout,setting "preferredContentSize".I really wanted to know whether I'm doing wrong somewhere, or it is not possible to have widget height more than screen height.Any suggestion is appreciated. Here is my code Todayviewcontroller.m

-(void)adjustWidgetHeight {
NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:self.view
                                                                    attribute:NSLayoutAttributeHeight
                                                                    relatedBy:0
                                                                       toItem:nil
                                                                    attribute:NSLayoutAttributeNotAnAttribute
                                                                   multiplier:1
                                                                     constant:2140];
heightConstraint.priority = 999;

[self.view addConstraint:heightConstraint];
[self.view needsUpdateConstraints];
[self.view setNeedsLayout];

}

iDev
  • 1,042
  • 13
  • 19
ayinala
  • 185
  • 1
  • 12

1 Answers1

2

The height can be dynamically changed, but I think it's not possible to reach a over-screen height.

the stock app is a preset app, so maybe can do that.

after I checked my widget demo code(I do some researches that how to create widget all by codes), i think it can not be done.

system will add a force constraint of height that exactly eqauls the widget panel ( in Iphone 5 & 5S , it's about 441), even I manually set 3000 height, it's still limited to 441.

you can check the demo gif:

test

it's my code for the test( I'm using Masonry to do autolayout)

//
//  TodayViewController.m
//  widget
//
//  Created by Ralph Li on 4/29/15.
//  Copyright (c) 2015 LJC. All rights reserved.
//

#import "TodayViewController.h"
#import <NotificationCenter/NotificationCenter.h>
#import <Masonry/Masonry.h>

@interface TodayViewController () <NCWidgetProviding>

@property (strong, nonatomic) UIView *contentView;
@property (nonatomic, strong) UIButton *btnTest;

@end

@implementation TodayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    self.contentView = [UIView new];
    self.contentView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.contentView];

    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
        make.height.mas_equalTo(200).priorityHigh();
    }];

    self.btnTest = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.btnTest setTitle:[[NSDate date] description] forState:UIControlStateNormal];
    self.btnTest.backgroundColor = [UIColor redColor];
    [self.btnTest addTarget:self action:@selector(actionTest) forControlEvents:UIControlEventTouchUpInside];

    [self.contentView addSubview:self.btnTest];

    [self.btnTest mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(300, 40));
    }];
}

- (void) actionTest
{
    [self.contentView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(@(self.contentView.frame.size.height>250?200:3000)).priorityHigh();
    }];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler {
    // Perform any setup necessary in order to update the view.

    // If an error is encountered, use NCUpdateResultFailed
    // If there's no update required, use NCUpdateResultNoData
    // If there's an update, use NCUpdateResultNewData

    completionHandler(NCUpdateResultNewData);
}

- (UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets
{
    return UIEdgeInsetsZero;
}

@end
Community
  • 1
  • 1
adali
  • 5,977
  • 2
  • 33
  • 40
  • Thanks adali..Me too able to change the height dynamically but not more than screen size.I really appreciate your effort. – ayinala Apr 29 '15 at 05:56
  • I was looking for `widgetPerformUpdateWithCompletionHandler ` , thanks – Husam Aug 30 '16 at 19:50