iOS implements the addition of a row row column button

Source: Internet
Author: User

Note the total number of buttons to be added is
-(void) addscrollandbutton{

int column=4;//number of columns

int total = self . Listarray. count;

int rows = (Total/column) + ((total% COLUMN) > 0? 1: 0);

int btnwidth=50;

int btnheight=30;

int widthblank=20;

int heightblank=20;

For (int i=0; i<total; i++) {

int row = I/column; //number of rows

int column = i% column; //Number of columns

// Add button

UIButton *abutton=[UIButton buttonwithtype: Uibuttontypecustom];

Abutton. frame=CGRectMake ((widthblank+btnwidth) *column, (heightblank+btnheight) *row, btnwidth, btnheight);

        Abutton. tag=1000+i;

        [Abutton settitle:[[[self. Listarray Objectatindex:i]objectforkey:@ "Table" ]objectforkey:@ "Title" "Forstate:uicontrolstatenormal

[Abutton settitlecolor: [uicolor graycolor] forstate: UIControlStateNormal];

[Abutton setshowstouchwhenhighlighted:YES]; set the highlight when pressed

[Abutton addTarget:self Action:@selector(buttonpressed:) forcontrolevents: UIControlEventTouchUpInside];

[self.view Addsubview:abutton];

}

}

-(void) buttonpressed: (ID) sender

{

UIButton * button = (UIButton *) sender;

int index=button. Tag-1000;

}

iOS implements the addition of a row row column button

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.