导航条的简单实现
2014-03-13 20:25
99 查看
#import "RootViewController.h"
@interface RootViewController ()
{
UIView *view;
UIView *view1;
UILabel *templabel;
UIScrollView *scroll;
}
@end
@implementation RootViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//创建UIScrollView
scroll=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 20, 320, 40)];
scroll.backgroundColor=[UIColor whiteColor];
scroll.scrollEnabled=YES;
scroll.contentSize=CGSizeMake(600, 41);
[self.view addSubview:scroll];
[scroll release];
//添加Label
NSArray *array=[[NSArray alloc]initWithObjects:@"经济",@"财经",@"NBA",@"汽车",@"热点",@"房产",@"科技",@"娱乐",@"美女",@"军事", nil];
for (int i=0; i<10; i++) {
NSString *str=[array objectAtIndex:i];
UITapGestureRecognizer *tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(change:)];
[self creatLabel:CGRectMake(60*i, 0, 60, 40) color:[UIColor whiteColor] superView:scroll title:str action:tapGesture];
}
//添加view,必须在label创建之后
//view=[[UIView alloc]initWithFrame:CGRectMake(10, 30, 40,5)];
view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 30)];
view.backgroundColor=[UIColor grayColor];
view.alpha=0.3;
[scroll addSubview:view];
view1=[[UIView alloc]initWithFrame:CGRectMake(0, 30, 50, 5)];
view1.backgroundColor=[UIColor redColor];
view1.alpha=1;
[scroll addSubview:view1];
}
-(void)creatLabel:(CGRect)Frame color:(UIColor*)color superView:(UIView *)superView title:(NSString *)title action:(UITapGestureRecognizer *)actionName
{
UILabel *label=[[UILabel alloc]initWithFrame:Frame];
label.userInteractionEnabled=YES;
label.textAlignment=NSTextAlignmentCenter;
label.backgroundColor=color;
[superView addSubview:label];
[label release];
[label addGestureRecognizer:actionName];
[actionName release];
label.text=title;
}
//NSInteger i=0;
- (void)change:(UITapGestureRecognizer *)tap
{
view.frame=tap.view.frame;
view1.center=CGPointMake(tap.view.center.x,tap.view.center.y+15);
// count++;
// if (count==1) {
// templabel=(UILabel *)(tap.view);
//
// }
// if (count>1) {
// templabel.backgroundColor=[UIColor whiteColor];
// }
// UILabel *curlabel=(UILabel *)(tap.view);
// curlabel.backgroundColor=[UIColor brownColor];
// templabel=curlabel;
}
-(void)dealloc
{
[view release];
[view1 release];
[templabel release];
[scroll release];
[super dealloc];
}
相关文章推荐
- Hbuilder开发APP(一)——底部导航条简单实现
- jquery简单实现鼠标经过导航条改变背景图
- js实现带简单弹性运动的导航条
- 简单快速实现导航条(Viewpager+Fragment+Radiogroup)
- xq_navbar简单实现依赖于jQuery自定义快捷的炫酷导航条效果
- android实现简单底部导航条
- iOS - 网易新闻音乐滑动导航条实现(代码简单,自定义扩展)
- 树状结构导航条css+javascript简单实现
- 导航条(带下拉)简单实现;不喜勿喷!
- android字母导航条的简单实现
- iOS下简单实现滑动导航条
- iOS音频播放 (六):简单的音频播放器实现
- 超级简单的Android Studio jni 实现(无需命令行)
- 实现简单日历功能
- 【笔记】一个实现多连接的蓝牙BLE的简单封装
- c++中图的遍历,dfs和bfs的简单实现
- 【C++】迷宫的简单实现
- Angular实现的简单定时器功能示例
- 简单实现SVN增量备份