今天折腾了半天的问题,百尺竿头更进一步.
1.追根溯源
UIalertcontroller里面添加的textfield旁边会有两个黑色的框,自己拆视图(Debug View 就是xcode的功能)发现里面有一个tableview.里面cell的背景色是黑色
2.找它
2.1>通过runtime 找不到这个tableView
unsigned int numIvars; //成员变量个数
Ivar *vars = class_copyIvarList(NSClassFromString(@"UIAlertController"), &numIvars);
//Ivar *vars = class_copyIvarList([UIView class], &numIvars);
NSString *key=nil;
for(int i = 0; i < numIvars; i++) {
Ivar thisIvar = vars[i];
key = [NSString stringWithUTF8String:ivar_getName(thisIvar)]; //获取成员变量的名字
NSLog(@"variable name :%@", key);
key = [NSString stringWithUTF8String:ivar_getTypeEncoding(thisIvar)]; //获取成员变量的数据类型
NSLog(@"variable type :%@", key);
}
free(vars);
2.2>循环遍历子视图
首先判断是不是8的系统
if (SYSTEM_VERSION_LESS_THAN(@"9.0"))
{//循环遍历方法
[self wipeOutBlackColorInIOS8WithView:alert.view];
}
-(void)wipeOutBlackColorInIOS8WithView:(UIView *)fatherview
{
for (UIView *view in fatherview.subviews)
{
NSLog(@"view_class:%@",NSStringFromClass([view class]));
if ([NSStringFromClass([view class]) isEqualToString:@"_UIAlertControllerShadowedScrollView"])
{
}
if ([view isKindOfClass:[UITableView class]])
{
UITableView *tableView =(UITableView *)view;
NSInteger sections = tableView.numberOfSections;
for (int section = 0; section < sections; section++)
{
NSInteger rows =[tableView numberOfRowsInSection:section];
for (int row = 0; row < rows; row++)
{//找到tableView 改变cell背景色
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
UITableViewCell *cell =[tableView cellForRowAtIndexPath:indexPath];
[cell setBackgroundColor:kClearColor];
}
}
}
else
{
if (view.subviews.count)
{
[self wipeOutBlackColorInIOS8WithView:view];
}
}
}
}
坚持就是胜利