iOS widgets similar to Android notification settings after flags for notification.flag_ongoing_event
OK, about to know what it means, now you can start the code.
1. Create Widgets
Target: Xcode menu, File, New. Select Today Extension
-
2. Set the pure Code widget in the plist file
- Remove the Nsextensionmainstoryboard field
- Add the Nsextensionprincipalclass field, set value to Todayviewcontroller, and, of course, set other Viewcontroller
3. Select today when you are running
4. Add some controls to see the effect
- (void) viewdidload {[Super viewdidload]; //Add a button and click the button to change the color of the backgroundUIButton *button =[UIButton Buttonwithtype:uibuttontypesystem]; [Button Settitle:@"Click"Forstate:uicontrolstatenormal]; Button.backgroundcolor=[Uicolor Whitecolor]; [Button addtarget:self action: @selector (ClickAction) forcontrolevents:uicontroleventtouchupinside]; Button.frame= CGRectMake ( -,Ten, -, -); [Self.view Addsubview:button]; }- (void) clickaction{Self.view.backgroundColor=[Uicolor Redcolor];}
Effect
See you will find that the left side is empty a large chunk, because the Widget default will have a inset, rewrite the following method is good
-(Uiedgeinsets) Widgetmargininsetsforproposedmargininsets: (uiedgeinsets) defaultmargininsets { return Uiedgeinsetszero;}
The final effect is as follows:
If you do not see this article in the wb145230 Blog Park, please click here to view the original.
IOS widgets Simple to use