Mainly this page, the main functions of the implementation are: 1. Click on the above title bar, the bottom of the red scroll bar followed by the click of the title below, 2 in the middle of the picture to cycle automatically, 3, click on the following tabs to add the clicked tag to the above title bar, 4 When you click on the tag below to remove it from the above title bar when it already exists
Viewdidload inside calls various methods-(void) viewdidload{ //Do any additional setup after loading the view. Self.titlearray = [Nsmutablearray arraywithobjects:@ "headline", @ "World Cup", @ "recommended", @ "Entertainment", @ "Sports", @ "Finance", nil]; [Self setuptopview];//sets the topmost red view [self setupscrollview];//sets the title bar under the Red View [self setupimagescrollview];// Set the layout of the middle picture [self setuppagecontrol];//set the Pagecontrol in the lower right corner of the picture [self setuplabel];//set the middle "add tag" [Self setupallbutton];//set all tags at the bottom [nstimer scheduledtimerwithtimeinterval:0.5 target:self selector: @selector ( Cycleplay) Userinfo:nil repeats:yes];//Use the timer to achieve the loop playback of the picture}
-(void) setuptopview{ UIView *redview = [[UIView alloc]initwithframe:cgrectmake (0, 0, Max.)]; Redview.backgroundcolor = [Uicolor redcolor]; [Self.view Addsubview:redview]; [Redview release]; UILabel *label = [[UILabel alloc]initwithframe:cgrectmake (+, +)]; Label.text = @ "NetEase News"; [Redview Addsubview:label]; [Label release]; UIButton *button = [UIButton Buttonwithtype:uibuttontypesystem]; Button.frame = CGRectMake (280, +, +); [Button settitle:@ "+" forstate:uicontrolstatenormal]; Button.titleLabel.font = [Uifont systemfontofsize:40]; [Redview Addsubview:button];}
Set the title bar above scrollview-(void) setupscrollview{Self.scrollview = [[Uiscrollview alloc]initwithframe:cgrectmake (0, 60, 320, 30)]; _scrollview.contentsize = Cgsizemake (640, 30); [Self.view Addsubview:_scrollview]; _scrollview.showsverticalscrollindicator = NO; for (int i = 0; i < [_titlearray count]; i++) {UIButton *button = [UIButton Buttonwithtype:uibuttontypesystem]; Button.frame = CGRectMake (i, 0, 50, 30); [Button settitle:_titlearray[i] forstate:uicontrolstatenormal]; [Button Settintcolor:[uicolor Blackcolor]; [Button addtarget:self action: @selector (Titleclick:) forcontrolevents:uicontroleventtouchupinside]; Button.tag = + i; Button.titleLabel.font = [Uifont systemfontofsize:15]; [_scrollview Addsubview:button]; } _scrollview.bounces = NO; _scrollview.tag = 300; Self.titleview = [[UIView alloc]initwithframe:cgrectmake (10, 27, 50, 3)]; _titleview.backgroundcolor = [Uicolor Redcolor]; [_scrollview Addsubview:_titleview]; [_titleview release];}
Set the Click event of the title bar key to ensure that the bottom progress bar and the above text sync-(void) Titleclick: (UIButton *) button{ _titleview.frame = CGRectMake ( Button.frame.origin.x, 27, 50, 3);}
</pre><pre name= "code" class= "OBJC" >//set the scrollview//of the middle picture while playing 3 pictures but for loop playback, set 5 space size, See http://blog.csdn.net/canyeyj/article/details/38963435-(void) setupimagescrollview{for details of how the loop is implemented Self.imagescrollview = [[Uiscrollview alloc]initwithframe:cgrectmake (0, 90, 320, 240)]; _imagescrollview.contentsize = Cgsizemake (320 * 5, 240); _imagescrollview.contentoffset = Cgpointmake (320, 0); for (int i = 0; i < 5; i++) {_imageview = [[Uiimageview alloc]initwithframe:cgrectmake (0, 320, 240)]; if (0 = = i) {_imageview.image = [UIImage imagewithcontentsoffile:[[nsbundle Mainbundle] Pathforresource : [NSString stringwithformat:@ "V6_guide_3"] oftype:@ "PNG"]; } else if (I >= 1 && i <= 3) {_imageview.image = [UIImage imagewithcontentsoffile:[[nsbundle mai Nbundle] pathforresource:[nsstring stringwithformat:@ "v6_guide_%d", I] oftype:@ "PNG"]; } else if (4 = = i) {_imageview.image = [UIImage ImagewIthcontentsoffile:[[nsbundle Mainbundle] pathforresource:[nsstring stringwithformat:@ "v6_guide_1"] ofType:@ "PNG"] ; }//_imageview.tag = + i; [_imagescrollview Addsubview:_imageview]; [_imageview release]; } _imagescrollview.tag = 150; _imagescrollview.showshorizontalscrollindicator = NO; _imagescrollview.showsverticalscrollindicator = NO; _imagescrollview.delegate = self; [Self.view Addsubview:_imagescrollview]; _imagescrollview.pagingenabled = YES; [_imagescrollview release];}
Set pagecontrol-(void) setuppagecontrol{ self.pagecontrol = [[Uipagecontrol alloc]initwithframe:cgrectmake (250 , 290, ())]; _pagecontrol.numberofpages = 3; _pagecontrol.currentpageindicatortintcolor = [Uicolor orangecolor]; _pagecontrol.pageindicatortintcolor = [Uicolor blackcolor]; _pagecontrol.tag =; [_pagecontrol addtarget:self Action: @selector (Handlepagecontrol:) forcontrolevents:uicontroleventvaluechanged]; [Self.view Addsubview:_pagecontrol]; [_pagecontrol release];}
Set Pagecontrol Click Event-(void) Handlepagecontrol: (Uipagecontrol *) pagecontrol{ Uiscrollview *scrollview = ( Uiscrollview *) [Self.view viewwithtag:150]; [ScrollView Setcontentoffset:cgpointmake (pagecontrol.currentpage + 1), 0) Animated:yes];} -(void) scrollviewdidenddecelerating: (Uiscrollview *) scrollview{ Uipagecontrol *pagecontrol = (UIPageControl *) [ Self.view viewwithtag:160]; Pagecontrol.currentpage = (scrollview.contentoffset.x --)/; int i = (scrollview.contentoffset.x --)/+ 1; if (0 = = i) { Scrollview.contentoffset = cgpointmake (3, 0); Pagecontrol.currentpage = 2; } else if (4 = = i) { scrollview.contentoffset = cgpointmake (0); pagecontrol.currentpage = 0; }}
Set Add tag block-(void) setuplabel{ _labelview = [[UIView alloc]initwithframe:cgrectmake (0, +/-)]; _labelview.backgroundcolor = [Uicolor colorwithred:255/225.0 green:182/225.0 blue:193/225.0 alpha:1.0]; [Self.view Addsubview:_labelview]; [_labelview release]; UILabel *label2 = [[UILabel Alloc]initwithframe:cgrectmake (Ten, Ten, +)]; Label2.Text = @ "add tag"; Label2.font = [Uifont systemfontofsize:15]; [_labelview Addsubview:label2]; [Label2 release]; }
</pre>//the button for each label below is a custom one that inherits from the UIButton class, setting the property flag<pre name= "code" class= "OBJC" >//set the option button below-(void) setupallbutton{ Nsarray *labelarray = @[@ "Technology", @ "easy moment", @ "digital", @ "fashion", @ "game", @ "original", @ "car", @ "CBA", @ "featured", @ "real estate", @ "mobile", @ "Home"]; int n = 0; for (int i = 0, i < 4; i++) {for (int j = 0; J < 3; J + +) { _button = [Yjbutton buttonwithtype:uibuttontype System]; _button.frame = CGRectMake (ten + i *, 430 + J * +, +); _button.backgroundcolor = [Uicolor lightgraycolor]; [_button Settintcolor:[uicolor Blackcolor]; _button.tag = + N; _button.flag = YES; [_button settitle:labelarray[n++] forstate:uicontrolstatenormal]; [Self.view Addsubview:_button]; [_button addtarget:self Action: @selector (click:) forcontrolevents:uicontroleventtouchupinside];}} }
Set the Click event for each of the following tabs-(void) Click: (Yjbutton *) button{ Uiscrollview *scrollview = (Uiscrollview *) [Self.view Viewwithtag : +]; [ScrollView Removefromsuperview]; if (button.flag) { [Self.titlearray addObject:button.currentTitle]; [Self setupscrollview]; Button.flag = NO; } else { [Self.titlearray removeObject:button.currentTitle]; [Self setupscrollview]; Button.flag = YES;} }
Timer playback Event-(void) cycleplay{ nsinteger pagenum = _pagecontrol.currentpage; pagenum++; if (Pagenum > 2) { pagenum = 0; } _pagecontrol.currentpage = Pagenum; [Self Handlepagecontrol:_pagecontrol];}
Memory processing-(void) dealloc{ [_titlearray release]; [_scrollview release]; [_titlearray release]; [_imagescrollview release]; [_pagecontrol release]; [Super Dealloc];}
iOS realizes NetEase News homepage