尝试将uibarbuttonstyleCamera在iOS6的

尝试将uibarbuttonstyleCamera在iOS6的

问题描述:

林添加到一个UITableViewCell试图将uibarbutton-相机样式添加到一个UITableViewCell编程像这样 ,但我没有看到任何东西在UITableViewCell中尝试将uibarbuttonstyleCamera在iOS6的

UIButton *newBtn=[UIButton buttonWithType:UIBarButtonSystemItemCamera]; 
     [newBtn setFrame:CGRectMake(250,10,50,30)]; 
     [newBtn addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside]; 
     [newBtn setEnabled:YES]; 
     [cell addSubview:newBtn]; 

但是当我使用此代码,我看到一个圆角的矩形按钮,在UITableViewCell中

UIButton *newBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
     [newBtn setFrame:CGRectMake(250,10,50,30)]; 
     [newBtn addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside]; 
     [newBtn setEnabled:YES]; 
     [cell addSubview:newBtn]; 

有什么办法,我可以添加一个按钮uibarbuttonstyle或所有我能做的就是添加一个UIButton圆角的矩形风格到的UITableViewCell?

UIBarButtonItemUIButton不一样。它甚至不会从UIView继承,因此您不能将其作为子视图添加到其他视图。当你调用

[UIButton buttonWithType:UIBarButtonSystemItemCamera] 

就是UIBarButtonSystemItemCamera常量是buttonWithType:无效值,这样的UIButton不能决定哪些类型的按钮返回,会发生什么 - 也许它只是返回一个空的,没有配置一个或nil

因此,解决您的问题并不容易。你可以做的是,例如,拿相机栏按钮项目的截屏,然后用某种图像编辑器应用程序中提取的图像,然后设置图片作为自定义UIButton像这样的形象:

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 
[btn setImage:[UIImage imageNamed:@"Camera.png"] forState:UIControlStateNormal]; 
[cell.contentView addSubview:btn]; 
+0

啊。我懂了。好的,非常感谢你澄清这一点。 – banditKing 2013-02-19 06:33:24