标签:
先上图,大家可以看下我做的效果图。
1.我已经做了屏幕适配了,首先获取屏幕的宽和高,
CGRect rect = [[UIScreen mainScreen] bounds];
ScWidth = rect.size.width;
ScHeight = rect.size.height;
设置控件frame的时候,我尽量使用到这两个变量。
2.我使用了导航控制器来push弹出来的窗口视图,分别使用到来显示广告的控制器,显示详细新闻的控制器,显示彩票的控制器,显示导航目录的控制器等。。。
在首页,为来美观,我没有让导航栏显示出来。
使用的语句是:
[self.navigationController setNavigationBarHidden:YES];
3.我分别使用来广告轮播跟图片新闻轮播的效果。
轮播的广告图片取自互联网:
//轮播广告
NSURL *Img1Url = [NSURL URLWithString:@"http://img1.126.net/channel6/2015/018439/640100_0105.jpg"];
UIImage *Img1 = [UIImage imageWithData:[NSData dataWithContentsOfURL:Img1Url]];
NSURL *Img2Url = [NSURL URLWithString:@"http://img1.126.net/channel6/640x100bbb.jpg"];
UIImage *Img2 = [UIImage imageWithData:[NSData dataWithContentsOfURL:Img2Url]];
NSURL *Img3Url = [NSURL URLWithString:@"http://img1.126.net/channel6/2015/018736/640100_0106.jpg"];
UIImage *Img3 = [UIImage imageWithData:[NSData dataWithContentsOfURL:Img3Url]];
admages1 = [[NSMutableArray alloc] initWithObjects:Img1,Img2,Img3,nil];
轮播使用了一个滚动视图:
scrollView1 =[[UIScrollView alloc] initWithFrame:CGRectMake(0, 25, ScWidth, 40)];
然后分别设置了图片的属性跟滚动视图的关系:
CGFloat imageW = self.scrollView1.frame.size.width;
CGFloat imageH = self.scrollView1.frame.size.height;
CGFloat imageY = 0; for(int i = 0;i<3;i++)
{
UIImageView *imageView = [[UIImageView alloc] init];
CGFloat imageX = i * imageW;
imageView.frame = CGRectMake(imageX, imageY, imageW, imageH);
imageView.image = [admages1 objectAtIndex:i];
scrollView1.showsHorizontalScrollIndicator = NO;
//scrollView1.showsVerticalScrollIndicator = NO;
[scrollView1 addSubview:imageView];
}
给轮播广告添加了点击事件:
UITapGestureRecognizer *tapGesture1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapFrom:)]; [scollView addGestureRecognizer:tapGesture1];
4.设置了新闻内容分类:
//设置内容分类按钮并且给每个分类添加点击事件
newsButtons = [[NSMutableArray alloc] initWithObjects: @"新闻",@"独家",@"体育",@"娱乐",@"女人",@"财经", @"汽车",@"手机",@"科技",@"游戏",@"军事",@"选股", @"图片",@"房产",@"数码",@"博客",@"邮箱",@"小说",nil];/////
for(int i=0;i<[newsButtons count];i++)
{
UIButton *btn4; btn4= [[UIButton alloc] initWithFrame:CGRectMake(10+(i%6)*50,65+(i/6)*30,49,30)];
[btn4 setTitle:[newsButtons objectAtIndex: i] forState:UIControlStateNormal];
[btn4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btn4 setTitleColor:[UIColor blueColor] forState:UIControlStateSelected];
btn4.enabled=YES;
[btn4 addTarget:self action:@selector(onClickTap:) forControlEvents:UIControlEventTouchUpInside]; [scollView addSubview: btn4];
}
5.给滚动新闻添加了半透明的内容提示:
UILabel *imgLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, ScWidth/2+155-20, ScWidth, 20)];
imgLabel.text = @" Hello Yan,this is a picture News!";
imgLabel.font = [UIFont systemFontOfSize: 10.0];
6.添加了两个新闻表视图:
在委托代理方法中对他们作以区分,以分别添加内容:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if(tableView == [detailTables objectAtIndex : 0]) {
...
}else{
....
}
同理在设置表视图单元格高度上,分别设置。。等等。。。。
[imgLabel setTintColor:[UIColor blackColor]];
6.添加文件下载按钮及下载方法:
NSString *urlAsString = @"http://files.cnblogs.com/zhuqil/UIWebViewDemo.zip";
NSURL *url = [NSURL URLWithString:urlAsString];
NSURLRequest *request = [NSURLRequest requestWithURL:url]; NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
/* 下载的数据 */
if (data != nil)
{ NSLog(@"下载成功");
if ([data writeToFile:@"UIWebViewDemo.zip" atomically:YES])
{
NSLog(@"保存成功.");
}
else
{
NSLog(@"保存失败.");
}
}
else { NSLog(@"%@", error);
}
欢迎大家批评,指教,谢谢!!!
标签:
原文地址:http://blog.csdn.net/u013773524/article/details/42683659