How to set the height of a Today Widget Extension?

后端 未结 6 1833
心在旅途
心在旅途 2020-12-12 18:13

How can i change the height of my App\'s Today Extension in the Notification Center?

I tried it with the Interface Builder and with Code, the Interface Builder Displ

6条回答
  •  没有蜡笔的小新
    2020-12-12 18:53

    In your widget UIViewController.m (Objective-C):

    self.preferredContentSize = CGSizeMake(0, 200);
    

    Will make your widget have a height of 200.

    Note that the width will have no affect on the view, as widgets must fit in the exact width of notification center, which is handled automagically.

    Also, if you want to animate changes in the height of your view, you can implement (Objective-C):

    - (void)viewWillTransitionToSize:(CGSize)size
           withTransitionCoordinator:(id)coordinator
    

    in your view controller using -animateAlongsideTransition:completion:

    The answer was a bit hidden; you had to click around in the documentation sidebar to eventually find this fantastic document.


    Another way is to use auto-layout constraints to constrain your view's height.

提交回复
热议问题