iOS form maker

Source: Internet
Author: User

Due to the requirements on the project, a table is needed to show the status of the process. At the beginning of the brain confused, there is no idea, but by their own motto-"Nothing is difficult, I'm afraid of the conscientious", overcome all the difficulties. OK, no, tell me about it.

Make a form, or you need tableview to do it.

1. Create a UIView object;

UIView *tableviewheadview=[[UIView alloc]initwithframe:cgrectmake( 0, 0, kcount*kwidth, kheight)];

Self. Myheadview=tableviewheadview; (Myheadview is UIView)

2. Create a View object of n fields and place it on the Tableviewheadview created above;

for (int i=0;i<kcount; i++) {

UIView *headview=[[UIView alloc]initwithframe:cgrectmake(i* Kwidth, 0, kwidth, kheight)];

Headview. BackgroundColor =[uicolorcolorwithred:arc4random_uniform(255)/ 255.0green:arc4random_uniform(255)/255.0 Blue:arc4random_uniform(255)/255.0Alpha: 1];

[Tableviewheadview Addsubview: Headview];

}

3. Then create a UITableView object;

uitableview *tableview=[[uitableviewalloc]initwithframe: CGRectMake(0, 0, self. Myheadview . Frame . size . width , 460 ) style:uitableviewstyleplain];

TableView. delegate=self;

TableView. DataSource=self;

TableView. bounces=YES;

TableView. Separatorstyle = Uitableviewcellseparatorstylenone;

Self. Mytableview=tableview;

TableView. BackgroundColor=[uicolorwhitecolor];

4. Create a Uiscrollview object, place the above TableView object, and move its position to the right part of the pixel;

uiscrollview *myscrollview=[[uiscrollviewalloc]initwithframe: cgrectmake(kwidth*0.7, 0 , Self . View. Frame. Size. Width-kwidth*0.7, 480)];

[Myscrollview Addsubview: TableView];

Myscrollview. contentsize=cgsizemake(self. Myheadview. frame. size. width,0);

Myscrollview. bounces=YES;

[Self.view Addsubview:myscrollview];

5. Create columns for the leftmost field of the table;//Someone would ask, why not show it together in the TableView. Here, what I want to tell you is that in order to achieve, the first column of the table does not move, the other columns can slide the effect, so this is done. This is the most important step, that is, to achieve the first column of rolling, to ensure that the whole tableview and the first column sliding at the same time, this is my 6th step to achieve;

self. Timeview =[[timeview alloc]initwithframe:cgrectmake (0, kwidth*0.7, Kcount* (kheight+kheightmargin))]; Inside the Timeview class, a tableview is created.

[Self. View addsubview:self. Timeview];

6. Realizing the delegate of Uiscrollview

-(void) Scrollviewdidscroll: (uiscrollview *) ScrollView

{

cgfloat offsety= self. Mytableview . Contentoffset. Y;

cgpoint timeoffsety=self. Timeview. Timetableview. Contentoffset;

Timeoffsety. y=offsety;

self. Timeview. Timetableview. Contentoffset =timeoffsety;

if (offsety==0) {

self. Timeview . Timetableview . Contentoffset=Cgpointzero;

}

}

7. The next step is to achieve TableView delegate and DataSource.

To illustrate here, MyCell the initialization method of this class and creates n view

-(ID) Initwithstyle: (uitableviewcellstyle) style Reuseidentifier: (nsstring *) Reuseidentifier

{

self = [super initwithstyle: Style reuseidentifier: Reuseidentifier];

if (self) {

for (int i=0;i<; i++) {

            UIView*headview=[[UIViewAlloc]initWithFrame:CGRectMake(i*Kwidth, 0, Kwidth-Kwidthmargin, Kheight+Kheightmargin)];

Headview. backgroundcolor=[uicolor whitecolor];

[Self. Contentview addsubview: Headview];

}

}

returnself;

}

-(Nsinteger) TableView: (uitableview *) TableView numberofrowsinsection: (nsinteger ) Section

{

return Kcount-1;

}

-(uitableviewcell *) TableView: (uitableview *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath

{

Static nsstring *cellidentifier=@ "cell";

MyCell *cell = [TableView dequeuereusablecellwithidentifier: Cellidentifier];

if (cell==Nil) {

cell=[[mycellalloc]initwithstyle: Uitableviewcellstyledefaultreuseidentifier: cellidentifier];

cell. BackgroundColor=[uicolorgraycolor];

Cell.selectionstyle=uitableviewcellselectionstylenone;

[Cell setselectionstyle:uitableviewcellselectionstyledefault];

}

return cell;

}

8. Finally asynchronously needs to be the 1th step, the creation of the Headerview, placed to the table header, and set the height of the table head;

-(UIView *) TableView: (uitableview *) TableView viewforheaderinsection: (nsinteger) Section

{

returnself. Myheadview ;

}

-(cgfloat) TableView: (uitableview *) TableView heightforheaderinsection: (Nsinteger ) Section

{

returnkheight;

}

Here just wrote a very simple form, did not fill in the data, the subsequent will add in ...

Related Article

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.