从superView获取特定类型视图的所有元素

Kir*_*ari 0 iphone objective-c ios

我有一个UITableView.

UITableView包含

  1. UITextView
  2. UICollectionView
  3. UILabel

现在,我希望得到所有UILabelsuperView.

怎么做?

小智 6

您可以使用以下代码获取TextView的所有子视图:

for(UIView * subView in myTextView.subviews ) // here write Name of you TextView 
{ 
     // Here You can Get all subViews of your TextView.
    // But For Check subview is UILabel or not ? write following code also.

        if([subView isKindOfClass:[UILabel class]]) // Check is SubView Class Is UILabel class
        {
            // You can write code here for your UILabel;
        }
}
Run Code Online (Sandbox Code Playgroud)