How to get a certain subview from UIView by tag

前端 未结 6 1109
野趣味
野趣味 2021-02-03 21:00

I\'m a noob in Objective-C and I have one question.

I have one UILabel object that I adding to one UIView with this code:

UILabel *label = [         


        
6条回答
  •  时光说笑
    2021-02-03 21:38

    You can get your subviews with for loop iteration

    for (UIView *i in self.view.subviews){
          if([i isKindOfClass:[UILabel class]]){
                UILabel *newLbl = (UILabel *)i;
                if(newLbl.tag == 1){
                    /// Write your code
                }
          }
    }
    

    Swift

    let label:UILabel = self.view.viewWithTag(1) as! UILabel
    

提交回复
热议问题