IOS Widgets Simple to use

Source: Internet
Author: User

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

    1. Remove the Nsextensionmainstoryboard field
    2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.