iphone - Today's widget height dynamically - iOS -
i'm working on application uses today's widget need show table view 50 rows.but screen fits 10 rows.so need increase height of widget per table height.i've done lot of research on says me can't done.i've seen yahoo stocks app,which has "show all" feature display stocks on widget height more of screen height.if done somewhere why can't that? i've tried set height of todayviewcontroller view height in both ways using autolayout,setting "preferredcontentsize".i wanted know whether i'm doing wrong somewhere, or not possible have widget height more screen height.any suggestion appreciated. here 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];
}
the height can dynamically changed, think it's not possible reach over-screen height.
the stock app preset app, maybe can that.
after checked widget demo code(i researches how create widget codes), think can not done.
system add force constraint of height eqauls widget panel ( in iphone 5 & 5s , it's 441), manually set 3000 height, it's still limited 441.
you can check demo gif:
it's code test( i'm using masonry autolayout)
// // todayviewcontroller.m // widget // // created ralph li on 4/29/15. // copyright (c) 2015 ljc. 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]; // additional setup after loading view 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 resources can recreated. } - (void)widgetperformupdatewithcompletionhandler:(void (^)(ncupdateresult))completionhandler { // perform setup necessary in order update view. // if error encountered, use ncupdateresultfailed // if there's no update required, use ncupdateresultnodata // if there's update, use ncupdateresultnewdata completionhandler(ncupdateresultnewdata); } - (uiedgeinsets)widgetmargininsetsforproposedmargininsets:(uiedgeinsets)defaultmargininsets { return uiedgeinsetszero; } @end
Comments
Post a Comment