480*320触屏320 480手机壁纸,带java如何...

网易新闻首页的实现,可以添加,移除标签,自动滚动图片,无限左右切换图片
RootViewController.h
Homework_163News
Created by lanouhn on 14-8-30.
Copyright (c) 2014年
陈聪雷. All rights reserved.
@interface RootViewController : UIViewController
@property (nonatomic, retain) NSMutableArray *
@property (nonatomic, retain) NSMutableArray *
RootViewController.m
Homework_163News
Created by lanouhn on 14-8-30.
Copyright (c) 2014年
陈聪雷. All rights reserved.
#import "RootViewController.h"
#import "NewsView.h"
@interface RootViewController ()
NSMutableArray *_
NSUInteger _imageC
@implementation RootViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
_isOrder = YES;
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changePage) userInfo:nil repeats:YES];
self.titles = [NSMutableArray arrayWithObjects:@"头条", @"世界杯", @"推荐", @"娱乐", @"体育", @"财经", nil];
self.labels = [NSMutableArray arrayWithObjects:@"科技", @"时尚", @"汽车", @"房产", @"轻松一刻", @"游戏", @"CBA", @"手机", @"数码", @"原创", @"精选", @"家居", nil];
_images = [NSMutableArray array];
for (int i = 0; i < 6; i++) {
UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"v6_guide_%d", i + 1]ofType:@"png"]];
[_images addObject:image];
_imageCount = _images.
- (void)loadView
NewsView *newsView = [[NewsView alloc] initWithFrame:[UIScreen mainScreen].bounds titles:self.titles images:_images labels:self.labels];
newsView.backgroundColor = [UIColor whiteColor];
self.view = newsV
- (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view.
UIScrollView *titleScrollView = (UIScrollView *)[self.view viewWithTag:100];
titleScrollView.delegate =
for (int i = 0; i < _titleC i++) {
UIButton *title = (UIButton *)[self.view viewWithTag:200 + i];
[title addTarget:self action:@selector(showLabel:) forControlEvents:UIControlEventTouchUpInside];
NewsView *newsView = (NewsView *)self.
newsView.imageView.scrollView.delegate =
[newsView.imageView.pageControl addTarget:self action:@selector(handlePageControl:) forControlEvents:UIControlEventValueChanged];
for (int i = 0; i < self.labels.count / 4; i++) {
for (int j = 0; j
_imageCount - 1 ? 0 :
newsView.imageView.pageControl.currentPage =
[newsView.imageView.scrollView scrollRectToVisible:CGRectMake(320 * (page + 1), 0, 320, newsView.imageView.scrollView.frame.size.height) animated:NO];
if (page) {
[newsView.imageView.scrollView setContentOffset:CGPointMake(320 * (page + 1), 0) animated:YES];
[newsView.imageView.scrollView setContentOffset:CGPointMake(320 * (page + 1), 0) animated:NO];
NewsView *newsView = (NewsView *)self.
int page = newsView.imageView.pageControl.currentP
if (_isOrder) {
page = page > _imageCount - 1 ? 0 :
if (!page) {
_isOrder = NO;
page = _imageCount - 2;
page = page < 0 ? 0 :
if (!page) {
_isOrder = YES;
newsView.imageView.pageControl.currentPage =
[newsView.imageView.scrollView setContentOffset:CGPointMake(320 * (page + 1), 0) animated:YES];
- (void)addLabel:(FlagButton *)btn
NSLog(@"%@", btn.currentTitle);
NewsView *newsView = (NewsView *)self.
[newsView.titleScrollView removeFromSuperview];
if (btn.flag) {
[self.titles addObject:btn.currentTitle];
[newsView setupTitleScrollView:self.titles];
btn.flag = NO;
[self.titles removeObject:btn.currentTitle];
[newsView setupTitleScrollView:self.titles];
btn.flag = YES;
- (void)didReceiveMemoryWarning
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
if (!self.view.window && [self isViewLoaded]) {
self.view =
- (void)dealloc
self.titles =
self.labels =
[super dealloc];
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
NewsView.h
Homework_163News
Created by lanouhn on 14-8-30.
Copyright (c) 2014年
陈聪雷. All rights reserved.
#import "LoopView.h"
#import "FlagButton.h"
@interface NewsView : UIView
@property (nonatomic, retain) NSMutableArray *
@property (nonatomic, retain) NSMutableArray *
@property (nonatomic, retain) LoopView *imageV
@property (nonatomic, retain) UIScrollView *titleScrollV
@property (nonatomic, retain) FlagButton *aL
- (void)setupTitleScrollView:(NSMutableArray *)
- (id)initWithFrame:(CGRect)frame titles:(NSMutableArray *)titles images:(NSMutableArray *)images labels:(NSMutableArray *)
NewsView.m
Homework_163News
Created by lanouhn on 14-8-30.
Copyright (c) 2014年
陈聪雷. All rights reserved.
#import "NewsView.h"
@interface NewsView ()
NSMutableArray *_
NSUInteger _titlesC
NSUInteger _imagesC
NSUInteger _labelsC
@implementation NewsView
- (id)initWithFrame:(CGRect)frame
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setupRedView];
[self setupTitleScrollView:self.titles];
[self setupImageView];
[self setupLabelView];
- (id)initWithFrame:(CGRect)frame titles:(NSMutableArray *)titles images:(NSMutableArray *)images labels:(NSMutableArray *)labels
self.titles =
self.labels =
_imagesCount = images.
_labelsCount = labels.
[self initWithFrame:frame];
- (void)setupRedView
UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
redView.backgroundColor = [UIColor colorWithRed:1.0 green:0.1 blue:0 alpha:0.5];
[self addSubview:redView];
[redView release];
UILabel *topical = [[UILabel alloc] initWithFrame:CGRectMake(130, 20, 70, 30)];
topical.text = @"网易新闻";
[redView addSubview:topical];
[topical release];
UIButton *add = [UIButton buttonWithType:UIButtonTypeSystem];
add.frame = CGRectMake(280, 28, 25, 25);
[add setTitle:@"+" forState:UIControlStateNormal];
[add setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
add.titleLabel.font = [UIFont systemFontOfSize:40];
[redView addSubview:add];
[add release];
- (void)setupTitleScrollView:(NSMutableArray *)titles
self.titles =
_titlesCount = titles.
int width = (320 - 5 * (_titlesCount + 1)) / _titlesC
int width = 47;
self.titleScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 60, 320, 40)];
_titleScrollView.backgroundColor = [UIColor colorWithRed:0.6 green:0.1 blue:0.0 alpha:0.2];
_titleScrollView.userInteractionEnabled = YES;
_titleScrollView.showsHorizontalScrollIndicator = NO;
_titleScrollView.tag = 100;
_titleScrollView.contentSize = CGSizeMake(320 + _titlesCount * width, _titleScrollView.bounds.size.height);
_titleScrollView.pagingEnabled = YES;
[self addSubview:_titleScrollView];
[_titleScrollView release];
int x = 5;
for (int i = 0; i < _titlesC i++) {
UIButton *title = [UIButton buttonWithType:UIButtonTypeSystem];
title.frame = CGRectMake(x, 5, width, 30);
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(x, title.frame.origin.y + title.frame.size.height, width, 2)];
title.userInteractionEnabled = YES;
title.tag = 200 +
line.tag = 300 +
title.titleLabel.font = [UIFont systemFontOfSize:15];
[title setTitle:self.titles[i] forState:UIControlStateNormal];
[title setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
x += width + 5;
[title addTarget:self action:@selector(showLabel:) forControlEvents:UIControlEventTouchUpInside];
[self.titleScrollView addSubview:title];
[self.titleScrollView addSubview:line];
[line release];
- (void)showLabel:(UIButton *)btn
UILabel *line = (UILabel *)[self viewWithTag:btn.tag + 100];
for (int i = 0; i < self.titles. i++) {
UILabel *otherLine = (UILabel *)[self viewWithTag:300 + i];
otherLine.backgroundColor = [UIColor clearColor];
line.backgroundColor = [UIColor redColor];
- (void)setupImageView
self.imageView = [[LoopView alloc] initWithFrame:CGRectMake(0, 100, 320, 280) images:_images];
[self addSubview:_imageView];
[_imageView release];
- (void)setupLabelView
UILabel *addLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 380, 320, 50)];
addLabel.backgroundColor = [UIColor colorWithRed:0.6 green:0.1 blue:0.0 alpha:0.2];
addLabel.text = @"添加标签";
[self addSubview:addLabel];
[addLabel release];
for (int i = 0; i < _labelsCount / 4; i++) {
for (int j = 0; j < 4; j++) {
self.aLabel = [FlagButton buttonWithType:UIButtonTypeSystem];
_aLabel.flag = YES;
_aLabel.frame = CGRectMake(5 + j * 80, 450 + i * 40, 73, 20);
_aLabel.backgroundColor = [UIColor lightGrayColor];
_aLabel.tag = 600 + 4 * i +
_aLabel.layer.cornerRadius = 2;
[_aLabel setTitle:self.labels[4 * i + j] forState:UIControlStateNormal];
[_aLabel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
_aLabel.titleLabel.font = [UIFont systemFontOfSize:18];
[self addSubview:_aLabel];
- (void)dealloc
self.aLabel =
self.labels =
self.titles =
self.imageView =
self.titleScrollView =
[super dealloc];
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
// Drawing code
LoopView.h
Test_LoopScrollView
Created by lanouhn on 14-8-30.
Copyright (c) 2014年
陈聪雷. All rights reserved.
@interface LoopView : UIView
@property (nonatomic, retain) UIScrollView *scrollV
@property (nonatomic, retain) UIPageControl *pageC
- (id)initWithFrame:(CGRect)frame images:(NSMutableArray *)
LoopView.m
Test_LoopScrollView
Created by lanouhn on 14-8-30.
Copyright (c) 2014年
陈聪雷. All rights reserved.
#import "LoopView.h"
@interface LoopView ()
NSMutableArray *_
NSUInteger _imagesC
@implementation LoopView
- (id)initWithFrame:(CGRect)frame
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setupScrollView];
[self setupPageControl];
- (id)initWithFrame:(CGRect)frame images:(NSMutableArray *)images
_imagesCount = images.
[self initWithFrame:frame];
- (void)setupScrollView
self.scrollView = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds];
_scrollView.tag = 400;
_scrollView.contentSize = CGSizeMake(320 * (_imagesCount + 2), [UIScreen mainScreen].bounds.size.height);
[_scrollView scrollRectToVisible:CGRectMake(320,0,320,[UIScreen mainScreen].bounds.size.height) animated:NO];
[_scrollView setContentOffset:CGPointMake(320, 0) animated:NO];
_scrollView.showsHorizontalScrollIndicator = NO;
_scrollView.pagingEnabled = YES;
[self addSubview:_scrollView];
[_scrollView release];
for (int i = 0; i < _imagesCount + 2; i++) {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(320 * i, 0, 320, self.frame.size.height)];
if (i == 0) {
imageView.image = [UIImage imageNamed:@"v6_guide_6"];
} else if (i == _imagesCount + 1) {
imageView.image = [UIImage imageNamed:@"v6_guide_1"];
imageView.image = _images[i - 1];
[_scrollView addSubview:imageView];
[imageView release];
- (void)setupPageControl
self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(10, self.frame.size.height - 40, 300, 20)];
_pageControl.tag = 500;
_pageControl.numberOfPages = 6;
_pageControl.currentPage = 0;
_pageControl.pageIndicatorTintColor = [UIColor grayColor];
_pageControl.currentPageIndicatorTintColor = [UIColor orangeColor];
[self addSubview:_pageControl];
[_pageControl release];
- (void)dealloc
self.scrollView =
self.pageControl =
[super dealloc];
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
// Drawing code
FlagButton.h
Homework_163News
Created by lanouhn on 14-8-30.
Copyright (c) 2014年
陈聪雷. All rights reserved.
@interface FlagButton : UIButton
@property (nonatomic, assign) BOOL
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467142',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'

参考资料

 

随机推荐