ios-Package pop-up box

Source: Internet
Author: User

1. Package Pop-up box, including setting pop-up screen to set pop-up location popup disappears and so on. Probably encapsulated as follows

#import <UIKit/UIKit.h> @interface wbdropdownmenu:uiview@property (nonatomic,strong) UIView *contentview;@ Property (Nonatomic,strong) Uiviewcontroller *cntcontroller;+ (instancetype) menu;-(void) Showfrom: (UIView *) view;-( void) dismiss; @end

2. Its implementation is as follows:

#import "WBDropdownMenu.h" @interface Wbdropdownmenu () @property (nonatomic, weak) Uiimageview *containerview;@ End@implementation wbdropdownmenu-(Uiimageview *) containerview{if (!_containerview) {Uiimageview *iv=[[UIImage        View alloc] init];        Iv.image=[uiimage imagenamed:@ "Popover_background"];        iv.width=217;        [Self addsubview:iv];    _containerview=iv; } return _containerview;}    #pragme Initialize transparent background interface and popup box background-(Instancetype) initWithFrame: (cgrect) frame{self = [super Initwithframe:frame];        if (self) {self.frame=[uiscreen mainscreen].bounds;                Self.backgroundcolor=[uicolor Clearcolor];    [Self containerview].userinteractionenabled=yes; } return self;} + (Instancetype) menu{return [[Wbdropdownmenu alloc] init];}    #pragme Set Popup contents-(void) Setcontentview: (UIView *) contentview{contentview.x=10;        contentview.y=15;    Contentview.width=self.containerview.width-2 * contentview.x; Self.containerview.height=cgrectgetmaxy (cOntentview.bounds) +25; [Self.containerview Addsubview:contentview];} -(void) Touchesbegan: (Nsset *) touches withevent: (uievent *) event{[self Dismiss];} Another form of #pragme extended content view viewcontroller-(void) Setcntcontroller: (Uiviewcontroller *) cntcontroller{_cntcontroller=    Cntcontroller; [Self setcontentview:_cntcontroller.view];} #pragme set the display position to the absolute position of the Windiow-(void) Showfrom: (UIView *) view{uiwindow *window= [[UIApplication sharedapplication].    Windows Lastobject];    [Window addsubview:self];    CGRect Absrect=[view convertRect:view.bounds toview:self];    Self.containerview.y=cgrectgetmaxy (Absrect);    Self.containerview.midx=cgrectgetmidx (Absrect); }-(void) dismiss{[self removefromsuperview];} @end

3. The call is as follows:

Self.menu=[wbdropdownmenu menu];        Wbdropdownviewcontroller *tableviewcontroller=[[wbdropdownviewcontroller alloc] init];    tableviewcontroller.tableview.height=44*3;        [Self.menu Setcntcontroller:tableviewcontroller];        [Self.menu Showfrom:target];


(Most pop-up boxes appear as the contents of the current top window, and a keyboard window is started by default in iOS8)

ios-Package pop-up box

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.