定制UIBarButtonItem

在使用 UIBarButtonItem  系统提供的几个函数的时发现添加背景图片后会有个小框,而且很难去掉,影响效果,而且UIBarButtonItem好像不能使用frame  的属性,所以可以下面方法定制自己的UIBarButtonItem

    1. UIImage* image= [UIImage imageNamed:@"绑定弹出-返回.png"]; 
    2.         CGRect frame_1= CGRectMake(0, 0, image.size.width, image.size.height-4); 
    3.         UIButton* backButton= [[UIButton alloc] initWithFrame:frame_1]; 
    4.         [backButton setBackgroundImage:image forState:UIControlStateNormal]; 
    5.         [backButton setTitle:@"返回" forState:UIControlStateNormal]; 
    6.         [backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
    7.         backButton.titleLabel.font=[UIFont systemFontOfSize:16]; 
    8.         [backButton addTarget:self action:@selector(doBack:) forControlEvents:UIControlEventTouchUpInside]; 
    9.         
    10. //定制自己的风格的 UIBarButtonItem
    11. UIBarButtonItem* someBarButtonItem= [[UIBarButtonItem alloc] initWithCustomView:backButton]; 
    12.         [self.navigationItem setLeftBarButtonItem:someBarButtonItem]; 
    13.         [someBarButtonItem release]; 
    14.         [backButton release];

posted on 2012-11-12 13:39  无量少年  阅读(206)  评论(0编辑  收藏  举报

导航