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 = [[UILabel alloc] initWithFrame:CGRectMake(0,10,self.view.frame.size.width-15-70, 30)]; label.tag = 1; label.font = [PublicObject fontTexts:17]; label.textAlignment = NSTextAlignmentRight; label.textColor = [UIColor whiteColor]; [cell setBackgroundColor:[UIColor clearColor]]; UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)]; view.backgroundColor = [PublicObject colorWithHexString:@"cd4110"]; label.text = [filterData objectAtIndex:indexPath.row]; view addSubview:label];
Now I want get one subview in my view where this subview has tag = 1 and save it on another object like this:
UILabel *tagLabel; tagLabel = // I want get one subview in view where tag = 1
Please help me understand how to do this.
The UIView class is a concrete class that you can instantiate and use to display a fixed background color. You can also subclass it to draw more sophisticated content.
An integer that you can use to identify view objects in your application.
Example with UILabel
:
UILabel *label = (UILabel *)[self.view viewWithTag:1];
good luck!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With