从nib初始化一个view+读plist+遍历子视图

    UIView *aView = [[[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil] lastObject];
[self.window addSubview:aView];

//打印数组,看你要的元素在哪里位置
NSLog(@"%@",[[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil]);



UISearchBar *aSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(10, 10, 200, 100)];

//改边框的颜色// 研究它到底有哪些视图
//方法一
[self allViews:aSearchBar index:0];
for (UIView *aView in aSearchBar.subviews)
{
if ([aView isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
[aView removeFromSuperview];
}
}

//方法二
//[[[aSearchBar subviews] objectAtIndex:0] removeFromSuperview];

[self.window addSubview:aSearchBar];


//找路径
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"plist"];
//从文件读
NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:plistPath];

NSLog(@"%@",dic);




-(void)allViews:(UIView *)aView index:(NSInteger)index
{
NSLog(@"[-] %@",index,aView);
index++;
for (UIView *aiew in aView.subviews)
{
[self allViews:aiew index:index];
}
}
posted @ 2011-09-15 23:57  wujian1360  阅读(865)  评论(0编辑  收藏  举报