Scrolling menu of pictures Scrolling news and news

Source: Internet
Author: User

If a scholar does not go out, he knows the world. Watching the news to understand the latest domestic and international developments, to master real-time information, is what we often do.

What kind of news provides a way to attract "scholar"? Intuitive feeling, clear direction is the basic requirements.

So, almost all of the big news pages and apps that contain scrolling picture news and News categories menu.

Image News add intuitive feel, category menu clear find direction. For example:

Draw on a mature news software, standing on the shoulders of giants. How is it implemented?

Two parts: Scrolling picture news + can scroll to select the News category menu.

1. Scrolling picture news: [Uiscrollview ...]

#pragmaMark-Load Picture scrolling view-(void) Setpicscrollview{uiscrollview* Picscroll=[[uiscrollviewalloc] Initwithframe:cgrectmake (0, titleviewy+ $, Kwidth, the)];_picscroll=Picscroll; Picscroll.contentsize=cgsizemake (kwidth* (_picarray.count+2),0); Picscroll.contentoffset=cgpointmake (Kwidth,0); Picscroll.showshorizontalscrollindicator=NO; Picscroll.pagingenabled=YES; Picscroll.Delegate=Self ; [Self.viewaddSubview:picScroll];//Add a previous page viewUiimageview * Preview=[[uiimageviewalloc] Initwithframe:cgrectmake (0,0, Kwidth, the)]; NSString* Path1=[[nsbundlemainbundle] Pathforresource:@"Mountain"OfType:@"jpg"]; Preview.image=[uiimageimagewithcontentsoffile:path1]; [Picscroll Addsubview:preview];//Add a later Page viewUiimageview * Lastview=[[uiimageviewalloc] Initwithframe:cgrectmake (kwidth*6,0, Kwidth, the)]; NSString* Path2=[[nsbundlemainbundle] Pathforresource:@"TS"OfType:@"jpg"]; Lastview.image=[Uiimageimagewithcontentsoffile:path2]; [Picscroll Addsubview:lastview]; for(intI=0; i<_picarray.count; i++) {Uiimageview* Img=[[uiimageviewalloc] Initwithframe:cgrectmake (kwidth* (i+1),0, Kwidth, the)]; NSString* path=[[Nsbundlemainbundle] pathforresource:_picarray[i] oftype:nil]; UIImage* image=[Uiimageimagewithcontentsoffile:path]; Img.image=image; [Picscroll addsubview:img]; UILabel* Describe=[[uilabelalloc] Initwithframe:cgrectmake (0,145,260, $)]; Describe.text=_plistarray[i][@"title"]; Describe.textcolor=[Uicolororangecolor];    [img Addsubview:describe]; }uipagecontrol* Pagecontrol=[[uipagecontrolalloc] Initwithframe:cgrectmake ( the, titleviewy+ $+ the- $, the, $)];_pagecontrol=Pagecontrol; Pagecontrol.numberofpages=5; Pagecontrol.pageindicatortintcolor=[Uicolorgreencolor]; Pagecontrol.currentpageindicatortintcolor=[Uicolorredcolor]; [Self.viewaddSubview:pageControl];}

2, refine the news category: [Uiscrollview ...]

//= = =---category title scrolling view---= = =Uiscrollview * Scrollview=[[uiscrollviewalloc] Initwithframe:cgrectmake (0, Titleviewy, Kwidth, $)]; Scrollview.backgroundcolor=[uicolorcolorwithred:0.5green:0.3blue:0.2alpha:0.6];_titlescroll=ScrollView; Scrollview.showshorizontalscrollindicator=NO; Scrollview.contentsize=cgsizemake ( About*_titlearray.count,0); [Self.viewaddSubview:scrollView]; for(intI=0; i<_titlearray.count; i++) {UIButton* Button=[[uibuttonalloc] Initwithframe:cgrectmake ( About*i,0, About, $)];        [Button settitle:_titlearray[i] forstate:uicontrolstatenormal]; Button.tag=i;        [Button Settitlecolor:[uicolorwhitecolor] forstate:uicontrolstatenormal];        [Button Settitlecolor:[uicolorgreencolor] forstate:uicontrolstateselected];        [Button addtarget:selfaction: @selector (Clickbutton:) forcontrolevents:uicontroleventtouchupinside];    [ScrollView Addsubview:button]; }}

Category of news menu, also note that to make the name of the currently selected news class font size or font change color, at this time, there are many ways to choose, in this "take only one scoop";

Use tag values and arrays to add and judge. difficult to achieve;

#pragmaMark-Add a Click event to the button-(void) Clickbutton: (UIButton *) Button{nsarray* array1=_titlescroll.subviews; Nsmutablearray* array=[Nsmutablearrayarraywitharray:array1]; [Array removelastobject]; for(UIButton * binchArray) {b.selected=NO;//NSLog (@ "%ld", B.tag);B.titlelabel.font=[uifontsystemfontofsize: -]; } button.selected=YES; Button.titleLabel.font=[uifontsystemfontofsize: -];    [Button Settitlecolor:[uicolor Greencolor] forstate:uicontrolstatenormal]; Button.titleLabel.adjustsFontSizeToFitWidth=YES;}

Of course, there are other ways to make it easy:

①: Use a button to record the previous selected button.

②: The tag value of the selected button is stored in the array, or the button is stored directly, if the button in the array changes state, otherwise, the state is restored.

A simple comb of pictures scrolling news and category News menu.

Scrolling menu of pictures Scrolling news and news

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.