#import "NewsView.h" @interface ViewController (){ NSArray *rssArray; } @property (strong, nonatomic) NewsView *newsView; @end @implementation ViewController @synthesize newsView; static int countInt=0; static NSString *notice_index; - (void)viewDidLoad { [super viewDidLoad]; newsView=[[NewsView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 100.0f)]; [self.view addSubview:newsView]; rssArray=parkEntity.notice_rows; notice_index=[[rssArray objectAtIndex:0] objectForKey:@"id"]; [newsView.titleLabel setText:[[rssArray objectAtIndex:countInt] objectForKey:@"title"]]; [newsView.descriptionLabel setText:@"TESTDESCRIPTION"]; [newsView.newsButton addTarget:self action:@selector(topNewsInfoClicked:) forControlEvents:UIControlEventTouchUpInside]; [UIView animateWithDuration:0.7 delay:0 options:0 animations:^(){ newsView.alpha = 0.2; [newsView exchangeSubviewAtIndex:1 withSubviewAtIndex:0]; newsView.alpha = 1; } completion:^(BOOL finished){ //设置定时器 [NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selector(displayNews) userInfo:nil repeats:YES]; }]; } -(void)displayNews{ countInt++; // long num = [rssArray count] >= 3 ? 3:[rssArray count]; if (countInt >= [rssArray count]) countInt=0; CATransition *animation = [CATransition animation]; animation.delegate = self; animation.duration = 0.5f ; animation.timingFunction = UIViewAnimationCurveEaseInOut; animation.fillMode = kCAFillModeForwards; animation.removedOnCompletion = YES; animation.type = @"cube"; notice_index=[[rssArray objectAtIndex:countInt] objectForKey:@"id"]; [newsView.layer addAnimation:animation forKey:@"animationID"]; [newsView setViewWithTitle:[[rssArray objectAtIndex:countInt] objectForKey:@"title"] description:@"test"]; } -(void)topNewsInfoClicked:(id)sender{ WebViewController *vc = [[WebViewController alloc] init]; vc.url = [NSString stringWithFormat:@"%@%@",PARKNOTICE_URL,notice_index]; vc.vcTitle = [[rssArray objectAtIndex:countInt] objectForKey:@"title"]; [self.navigationController pushViewController:vc animated:YES]; } @end
//NewsView.h // // NewsView.h // Created by Jack on 15-10-23. // Copyright (c) 2015年 Demo. All rights reserved. // #import <UIKit/UIKit.h> @interface NewsView : UIView @property (retain, nonatomic) UILabel *titleLabel; @property (retain, nonatomic) UILabel *descriptionLabel; @property (retain, nonatomic) UIButton *newsButton; -(void)setViewWithTitle:(NSString *)title description:(NSString *)description; @end
// NewsView.m // Created by Jack on 15-10-23. // Copyright (c) 2015年 Demo. All rights reserved. // #import "NewsView.h" @implementation NewsView @synthesize titleLabel; @synthesize descriptionLabel; @synthesize newsButton; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code //[self setBackgroundColor:[UIColor grayColor]]; titleLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 2, 211, 21)]; titleLabel.textColor=[UIColor grayColor]; titleLabel.backgroundColor=[UIColor clearColor]; titleLabel.font=[UIFont boldSystemFontOfSize:13.0]; // titleLabel.lineBreakMode = UILineBreakModeWordWrap; titleLabel.lineBreakMode = UILineBreakModeTailTruncation; titleLabel.numberOfLines = 1; [self addSubview:titleLabel]; descriptionLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 17, 260, 15)]; descriptionLabel.textColor=[UIColor blackColor]; descriptionLabel.backgroundColor=[UIColor clearColor]; descriptionLabel.font=[UIFont systemFontOfSize:11.0]; descriptionLabel.lineBreakMode = UILineBreakModeWordWrap; descriptionLabel.numberOfLines = 1; [self addSubview:descriptionLabel]; newsButton=[UIButton buttonWithType:UIButtonTypeCustom]; [newsButton setFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)]; [self addSubview:newsButton]; } return self; } -(void)dealloc{ // [titleLabel release]; // [descriptionLabel release]; // [super dealloc]; } -(void)setViewWithTitle:(NSString *)title description:(NSString *)description{ [titleLabel setText:title]; [descriptionLabel setText:description]; } @end
ps:参考
http://blog.csdn.net/totogo2010/article/details/8501812
原文:http://my.oschina.net/jack088/blog/521951