您的位置:首页 > 其它

导航条加阴影效果

2011-06-07 21:42 197 查看

想实现导航条有阴影效果,就是导航条看起来有立体感,阴影是渐渐变浅。有什么方法或者思路可以实现呢?
不要直接加图片的效果,

- (void)loadView {

self.title=@"testNav"; //设置当前标题
v1=[[UIView alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];

tableview=[[UITableView alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0) style: UITableViewStyleGrouped];
[tableview setDelegate:self];
[tableview setDataSource:self];
[tableview reloadData];
[v1 addSubview: tableview];

self.view=v1;
UIBarButtonItem *inputbutton = [[UIBarButtonItem alloc]initWithTitle:@"logoout" style:UIBarButtonItemStylePlain target:self action:@selector(bb)];
self.navigationItem.leftBarButtonItem = inputbutton;
CGRect frame = CGRectMake(0, 0, 400, 44);
label = [[[UILabel alloc] initWithFrame:frame] autorelease];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:20.0];
label.textColor = [UIColor whiteColor];
self.navigationItem.titleView = label;
label.text = NSLocalizedString(@"ステータス", @"");
topShadow = [[self shadowAsInverse:YES] retain];
[label.layer insertSublayer:topShadow atIndex:0];
}
- (CAGradientLayer *)shadowAsInverse:(BOOL)inverse
{
CAGradientLayer *newShadow = [[[CAGradientLayer alloc] init] autorelease];
CGRect newShadowFrame = CGRectMake(0.0, 44.0,400.0,inverse ? SHADOW_INVERSE_HEIGHT : SHADOW_HEIGHT);
newShadow.frame = newShadowFrame;
CGColorRef darkColor = [UIColor blackColor];
CGColorRef lightColor = [UIColor whiteColor];
newShadow.colors = [NSArray arrayWithObjects:lightColor,darkColor,nil];
return newShadow;
}
-(NSInteger)numberOfRowsInSection:(NSInteger)section//tableview输出的组数
{
NSLog(@"erqetwq");
return 3;
}

- (void)dealloc
{
[super dealloc];
}

#pragma mark UIViewController delegate methods

- (void)viewWillAppear:(BOOL)animated
{
NSIndexPath *tableSelection = [tableview indexPathForSelectedRow];
[tableview deselectRowAtIndexPath:tableSelection animated:NO];
}

#pragma mark UITableView delegate methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section//一组输出的几行数据
{
return 3;
}
//选择项后的事件响应
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

ButtonsViewController *buttonsViewController = [[ButtonsViewController alloc] init];
[self.navigationController pushViewController:buttonsViewController animated:YES];
NSLog(@"clicked item");
[ButtonsViewController release];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:kCellIdentifier] autorelease];
}
switch (indexPath.row) {
case 0:
cell.text = @"1 second view";
break;
case 1:
cell.text = @"2 second view";
break;
case 2:
cell.text = @"3 second view";
break;
default:
break;
}
return cell;
}

我是这样写的,但这个View还没加载完就崩溃了。麻烦高手指点一下吧

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: