zoukankan      html  css  js  c++  java
  • 图片滚动新闻和新闻的滚动菜单

      秀才不出门,便知天下事。看新闻了解国内、国际的最新动态,掌握实时资讯,是我们常常会做的事情。

      什么样的新闻提供方式能够吸引“秀才”呢?直观的感受、明确的方向是基本要求。

      于是,几乎所有的大型的新闻页面和应用程序,都包含滚动的图片新闻和新闻分类菜单。

      图片新闻增加直观感受,分类菜单明确查找方向。例如:

      借鉴一个成熟新闻软件,站在巨人的肩膀上。如何实现?

      两部分:滚动的图片新闻+可以滚动选择的新闻分类菜单。

    1.滚动的图片新闻:[UIScrollView  ...]

    #pragma mark - 加载图片滚动视图
    - (void) setPicScrollView{
    
    UIScrollView * picScroll=[[UIScrollViewalloc] initWithFrame:CGRectMake(0, titleViewY+45, kWidth, 190)];
    _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];
    
    //添加前一页视图
    UIImageView * preView=[[UIImageViewalloc] initWithFrame:CGRectMake(0, 0, kWidth, 190)];
    NSString     * path1=[[NSBundlemainBundle] pathForResource:@"mountain"ofType:@"jpg"];
        preView.image=[UIImageimageWithContentsOfFile:path1];
        [picScroll addSubview:preView];
    
    //添加后一页视图
    UIImageView * lastView=[[UIImageViewalloc] initWithFrame:CGRectMake(kWidth*6, 0, kWidth, 190)];
    NSString * path2=[[NSBundlemainBundle] pathForResource:@"ts"ofType:@"jpg"];
        lastView.image=[UIImageimageWithContentsOfFile:path2];
        [picScroll addSubview:lastView];
    
    for (int i=0; i<_picArray.count; i++) {
    
    UIImageView * img=[[UIImageViewalloc] initWithFrame:CGRectMake(kWidth*(i+1), 0, kWidth, 190)];
    
    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, 45)];
    
            describe.text=_plistArray[i][@"title"];
    
            describe.textColor=[UIColororangeColor];
    
            [img addSubview:describe];
        }
    
    UIPageControl * pageControl=[[UIPageControlalloc] initWithFrame:CGRectMake(270, titleViewY+45+190-45, 105, 45)];
    _pageControl=pageControl;
        pageControl.numberOfPages=5;
        pageControl.pageIndicatorTintColor=[UIColorgreenColor];
        pageControl.currentPageIndicatorTintColor=[UIColorredColor];
        [self.viewaddSubview:pageControl];
    
    
    }

    2,细化的新闻分类:[UIScrollView  ...]

    //===--- 分类标题滚动视图 ---===
    UIScrollView * scrollView=[[UIScrollViewalloc] initWithFrame:CGRectMake(0, titleViewY, kWidth, 45)];
        scrollView.backgroundColor=[UIColorcolorWithRed:0.5green:0.3blue:0.2alpha:0.6];
    _titleScroll=scrollView;
        scrollView.showsHorizontalScrollIndicator=NO;
        scrollView.contentSize=CGSizeMake(56*_titleArray.count, 0);
    
        [self.viewaddSubview:scrollView];
    
    for ( int i=0; i<_titleArray.count; i++) {
    UIButton * button=[[UIButtonalloc] initWithFrame:CGRectMake(56*i, 0, 56, 45)];
            [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];
        }
    
    
    }

      分类的新闻菜单,还要注意,要使当前选中的新闻类的名称字体变大或字体改变颜色,此时,有多种方法可以选择,在此“只取一瓢”;

     利用tag值和数组,添加、判断。艰难实现;

    #pragma mark - 为按钮添加点击事件
    - (void) clickButton:(UIButton *)button{
    
    NSArray * array1=_titleScroll.subviews;
    
    NSMutableArray * array=[NSMutableArrayarrayWithArray:array1];
    
           [array removeLastObject];
    
    
    for(UIButton * b in array){
    
                b.selected=NO;
    
    // NSLog(@"%ld",b.tag);
                b.titleLabel.font=[UIFontsystemFontOfSize:18];
            }
    
        button.selected=YES;
    
        button.titleLabel.font=[UIFontsystemFontOfSize:20];
      [ button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        button.titleLabel.adjustsFontSizeToFitWidth=YES;
    }

      当然,还有其他办法轻松实现:

    ①:用一个button,记录前一个选择的button。

    ②:数组中存放,选中的button的tag值或直接存放button,若数组中有该button就改变状态,否则,还原状态。

      图片滚动新闻和分类新闻菜单的简单梳理。

  • 相关阅读:
    【python-plt】二元正态密度函数图像
    【python-plt】一元正态分布图像
    【7】极大似然估计与贝叶斯估计
    实变函数【1】集合
    图形学-心得
    分布式网络架构
    shader的内置变量
    图形学-绘制
    python加载图片
    linux下批量删除utf8 bom
  • 原文地址:https://www.cnblogs.com/code-Officer/p/5631351.html
Copyright © 2011-2022 走看看