定制UIBarButtonItem
在使用 UIBarButtonItem 系统提供的几个函数的时发现添加背景图片后会有个小框,而且很难去掉,影响效果,而且UIBarButtonItem好像不能使用frame 的属性,所以可以下面方法定制自己的UIBarButtonItem
- UIImage* image= [UIImage imageNamed:@"绑定弹出-返回.png"];
- CGRect frame_1= CGRectMake(0, 0, image.size.width, image.size.height-4);
- UIButton* backButton= [[UIButton alloc] initWithFrame:frame_1];
- [backButton setBackgroundImage:image forState:UIControlStateNormal];
- [backButton setTitle:@"返回" forState:UIControlStateNormal];
- [backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- backButton.titleLabel.font=[UIFont systemFontOfSize:16];
- [backButton addTarget:self action:@selector(doBack:) forControlEvents:UIControlEventTouchUpInside];
- //定制自己的风格的 UIBarButtonItem
- UIBarButtonItem* someBarButtonItem= [[UIBarButtonItem alloc] initWithCustomView:backButton];
- [self.navigationItem setLeftBarButtonItem:someBarButtonItem];
- [someBarButtonItem release];
- [backButton release];