zoukankan      html  css  js  c++  java
  • 导航条加阴影效果

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

    - (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还没加载完就崩溃了。麻烦高手指点一下吧

  • 相关阅读:
    System.arraycopy用法
    Springmvc Get请求Tomcat、WebLogic中文乱码问题
    Rails内存的问题 Java内存情况
    Java 执行系统命令
    搭建Cocos2d-JS开发环境
    xcode 6 改动组织及开发人员
    poj
    hdu 4869 Turn the pokers (思维)
    【剑指offer】扑克牌的顺子
    NYOJ 480 Fibonacci Again!
  • 原文地址:https://www.cnblogs.com/chen1987lei/p/2074643.html
Copyright © 2011-2022 走看看