PopOver pop-up box easy to use (Imitation QQ pop-up box)

Source: Internet
Author: User
Tags uikit
popover Pop-up box simple to use 1. Imitation QQ pop-up box 1.1 Points of knowledge used 1.1.1 How to resize a pop-up box (this is also the controller that pops up here)

It's been explained here already. http://blog.csdn.net/iostiannan/article/details/51131431 1.1.2 How to make QQ pop-up box text and pop-up frame frame adaptive

"
This method returns a size that is obtained by calling the Uikit subclass, which is the perfect fit to call the size of the Uikit subclass of this method  
after this size is obtained, you can invoke the method to resize the frame * * preferredcontentsize** with
"//Reset the size of this controller
-(cgsize) preferredcontentsize{

    if ( Self.popoverpresentationcontroller!= nil) {
        cgsize tempsize;
        Tempsize.height = self.view.frame.size.height;
        Tempsize.width  = A;
        Cgsize size = [_tableview sizethatfits:tempsize];  Returns the size of a perfect fit tableview
        ;
    else{return
        [Super Preferredcontentsize];
    }




<div class= "Se-preview-section-delimiter" ></div>
The code is as follows VIEWCONTROLLER.M



<div class= "Se-preview-section-delimiter" ></div> #import "ViewController.h" <div class= "Se-preview -section-delimiter "></div> #import" PopViewController.h "@interface Viewcontroller () <


uipopoverpresentationcontrollerdelegate> {Popviewcontroller *_POPVC;
    @end @implementation Viewcontroller-(void) viewdidload {[Super viewdidload];



    Do no additional setup after loading the view, typically from a nib.
    Self.navigationItem.title = @ "QQ";

    Self.view.backgroundColor = [Uicolor Whitecolor];
    UIButton *BTNR = [UIButton buttonwithtype:uibuttontyperoundedrect];
    Btnr.frame = CGRectMake (0, 0, 50, 50);
    Btnr.backgroundcolor = [Uicolor Clearcolor];
    [Btnr settitle:@ "+" forstate:uicontrolstatenormal];
    [Btnr addtarget:self Action: @selector (Popview) forcontrolevents:uicontroleventtouchupinside];
    Uibarbuttonitem *imte = [[Uibarbuttonitem alloc] INITWITHCUSTOMVIEW:BTNR]; Self.navigationItem.rightBarButtonItem = Imte;


    }-(void) popview{_POPVC = [[Popviewcontroller alloc] init];

    _popvc.modalpresentationstyle = Uimodalpresentationpopover;

    Set the attached button _popvc.popoverpresentationcontroller.barbuttonitem = Self.navigationItem.rightBarButtonItem;

    You can indicate the small arrow color _popvc.popoverpresentationcontroller.backgroundcolor = [Uicolor Whitecolor];

    Content size _popvc.preferredcontentsize = Cgsizemake (400, 400);
    Pop direction _popvc.popoverpresentationcontroller.permittedarrowdirections = uipopoverarrowdirectionup;

    Delegate _popvc.popoverpresentationcontroller.delegate = self;



[Self PRESENTVIEWCONTROLLER:_POPVC animated:yes completion:nil]; //Agent method, click to dismiss off each init generated Popviewcontroller-(Uimodalpresentationstyle) Adaptivepresentationstyleforpresentationcontroller: (Uipresentationcontroller *) controller{return
Uimodalpresentationnone;
 } <div class= "Se-preview-section-delimiter" ></div>
pop-up box class. M



<div class= "Se-preview-section-delimiter" ></div> #import "PopViewController.h" @interface Popviewcontro
    Ller () <UITableViewDataSource,UITableViewDelegate> {UITableView *_tableview;
    Nsarray *_dataarray;
    Nsarray *_arr1;



Nsarray *_arr2;
    @end @implementation Popviewcontroller-(void) viewdidload {[Super viewdidload];

    Do no additional setup after loading the view.

    Self.view.backgroundColor = [Uicolor Whitecolor];
    _ARR1 = @[@ "Sweep", @ "add friend", @ "Create a discussion group", @ "Send to the computer", @ "face Fast Pass", @ "collect money"]; _ARR2 = @[@ "RIGHT_MENU_QR", @ "Right_menu_addfri", @ "Right_menu_multichat", @ "Right_menu_sendfile", @ "Right_menu_"



    Facetoface ", @" Right_menu_paymoney "];
    _tableview = [[UITableView alloc] initWithFrame:self.view.bounds];
    _tableview.delegate = self;
    _tableview.datasource = self;
    _tableview.scrollenabled = YES;
    _tableview.backgroundcolor = [Uicolor Whitecolor];



[Self.view Addsubview:_tableview]; }-(Nsinteger) TableView: (UITableView*) TableView numberofrowsinsection: (nsinteger) section{return _arr2.count; }-(uitableviewcell*) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexPath{static NSSt
    Ring *STR = @ "Cellid";
    UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:str];
    if (!cell) {cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:str];
    } Cell.textLabel.text = _arr1[indexpath.row];

    Cell.imageView.image = [UIImage imagenamed:[nsstring stringwithformat:@ "%@", _arr2[indexpath.row]];


return cell; }//Reset the size of this controller-(cgsize) preferredcontentsize{if (Self.popoverpresentationcontroller!= nil) {cgsize tempsi
        Ze;
        Tempsize.height = Self.view.frame.size.height;
        Tempsize.width = 155;  Cgsize size = [_tableview sizethatfits:tempsize];
    Returns the size of a perfect fit tableview;
    }else{return [Super Preferredcontentsize]; }}-(void) didreceivememorywarning {[Super didreceivememorywarning];
Dispose of any of the can is recreated. }/* <div class= "se-preview-section-delimiter" ></div> #pragma mark-navigation/in a storyboard-base  d application, you'll often want to do a little preparation before navigation-(void) Prepareforsegue: (Uistoryboardsegue
    *) Segue Sender: (ID) Sender {//Get the new view controller using [Segue Destinationviewcontroller].
Pass the selected object to the new view controller. } * * @end


SOURCE download ==>> GitHUb pragma mark-navigation

In a storyboard-based application, your'll often want to do a little preparation before navigation
-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {
Get the new view controller using [Segue Destinationviewcontroller].
Pass the selected object to the new view controller.
}
*/

@end
"'

Github===>>https://github.com/tiannanyihao/mytestdemo.git

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.