分组的UITableView的背景色在iOS7中不会变为透明
我正在开发一个应用程序,它在iOS 6上运行得非常好。在iOS7中,该应用程序存在一些布局和外观问题。无法将分组的tableview的背景色设置为透明。这是我不再工作的代码分组的UITableView的背景色在iOS7中不会变为透明,uitableview,transparency,ios7,xcode5,Uitableview,Transparency,Ios7,Xcode5,我正在开发一个应用程序,它在iOS 6上运行得非常好。在iOS7中,该应用程序存在一些布局和外观问题。无法将分组的tableview的背景色设置为透明。这是我不再工作的代码 tableForDetails = [[UITableView alloc]initWithFrame:CGRectMake(0, yAxisTable, 320, 150) style:UITableViewStyleGrouped]; UIColor *backGroundColor = [UIColor
tableForDetails = [[UITableView alloc]initWithFrame:CGRectMake(0, yAxisTable, 320, 150) style:UITableViewStyleGrouped];
UIColor *backGroundColor = [UIColor clearColor];
UIView *bview = [[UIView alloc]init];
[bview setBackgroundColor:backGroundColor];
[tableForDetails setBackgroundView:bview];
非常感谢您的帮助。感谢在iOS7中为分组的uiTableview设置背景透明度非常简单。这个解决方案比我原来想象的还要简单
[tableForDetails setBackgroundColor:[UIColor clearColor]];
或仅用于半透明
[tableForDetails setBackgroundColor:[[UIColor alloc]initWithRed:1.0 green:1.0 blue:1.0 alpha:0.5]];
这对我很管用 UITableViewCell在iOS 7中默认为白色背景 把这个放进你的牢房里 [cell setBackgroundColor:[UIColor clearColor]我用以下方法修复了它:
tableView.backgroundView = UIView.new;
我在一个超级类中对苹果组件进行了任何改进。BasicTableView.m中应用了以下升级,它扩展了
UITableView
:
1) 覆盖setBackgroundColor
以使用iOS 7及以上版本,同时保持与iOS 6及5的向后兼容性。2) 覆盖
initWithCoder:
和initWithFrame:style:
以将背景颜色初始化为默认透明背景- (id) initWithCoder:(NSCoder *)decoder
{
self = [super initWithCoder:decoder];
if (self) {
[self setup];
}
return self;
}
- (id) initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
self = [super initWithFrame:frame style:style];
if (self) {
[self setup];
}
return self;
}
- (void) setup
{
//Set the BG color to clear color by default
[self setBackgroundColor:[UIColor clearColor]];
}
- (void) setBackgroundColor:(UIColor *)backgroundColor
{
if (self.style == UITableViewStyleGrouped) {
if (majorSystemVersion() < 7) {
UIView *tableBgView = [[UIView alloc] init];
tableBgView.backgroundColor = backgroundColor;
self.backgroundView = tableBgView;
} else {
[super setBackgroundColor:backgroundColor];
}
}
}
//majorSystemVersion() is defined elsewhere in a utility file
int majorSystemVersion(void) {
NSString *systemVersion = [UIDevice currentDevice].systemVersion;
NSArray *systemVersionComps = [systemVersion componentsSeparatedByString:@"."];
NSString *majorVersion = [systemVersionComps objectAtIndex:0];
return [majorVersion intValue];
}
-(id)initWithCoder:(NSCoder*)解码器
{
self=[super initWithCoder:decoder];
如果(自我){
[自我设置];
}
回归自我;
}
-(id)initWithFrame:(CGRect)框架样式:(UITableViewStyle)样式
{
self=[super initWithFrame:frame-style:style];
如果(自我){
[自我设置];
}
回归自我;
}
-(无效)设置
{
//默认情况下,将背景颜色设置为“清除颜色”
[self-setBackgroundColor:[UIColor clearColor]];
}
-(无效)setBackgroundColor:(UIColor*)backgroundColor
{
if(self.style==UITableViewStyleGroup){
如果(主系统版本()<7){
UIView*tableBgView=[[UIView alloc]init];
tableBgView.backgroundColor=背景色;
self.backgroundView=tableBgView;
}否则{
[超级背景色:背景色];
}
}
}
//majorSystemVersion()在实用程序文件的其他位置定义
内部主系统版本(无效){
NSString*systemVersion=[UIDevice currentDevice].systemVersion;
NSArray*systemVersionComps=[SystemVersionComponentsSeparatedByString:@.”;
NSString*majorVersion=[systemVersionComps对象索引:0];
返回[majorVersion intValue];
}
IMHO尺寸不是关键要求。这同样适用于UIView*bgv=[[UIView alloc]init];bgv.backgroundColor=[UIColor clearColor];[self.tableView setBackgroundColor:[UIColor clearColor]];[self.tableView setBackgroundView:bgv];关键似乎是挫折。谢谢你的评论。我知道你是对的。我将编辑答案。