UIButton *playNowButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 64, 32)]; [playNowButton setBackgroundImage:[UIImage imageNamed:@"imagename.png"] forState:UIControlStateNormal]; [playNowButton addTarget:self action:@selector(doSomething)forControlEvents:UIControlEventTouchDown]; UIBarButtonItem *bar =[[UIBarButtonItem alloc] initWithCustomView:playNowButton]; [playNowButton release];
思路 创建一个UIButton将创建的UIButton作为UIBarButtonItem的参数传给UIBarButtonItem的初始化消息initWithCustomView中。
参考:http://mkhgg.blog.51cto.com/1741572/616479
http://stackoverflow.com/questions/2681321/uibarbuttonitem-with-custom-image-and-no-border