I have created dynamic UILabel
with tag value and i have similar kind of other labels without tag values.
Now i want access only tag values labels but i was not able to acces the label text value.
Here is my code.
Dynamic created Label
for (int i= 0; i < [array count]; i++) {
UILabel *defaultLbl = [[UILabel alloc] initWithFrame:CGRectMake(30, 70, 60, 21)];
defaultLbl.text = @"Default";
defaultLbl.backgroundColor = [UIColor clearColor];
defaultLbl.textColor = [UIColor colorWithRed:51.0/255.0 green:51.0/255.0 blue:51.0/255.0 alpha:1.0];
[defaultLbl setFont:[UIFont fontWithName:@"Helvetica" size:12]];
defaultLbl.textAlignment = NSTextAlignmentCenter;
defaultLbl.tag = i+1;
[myButton addSubview:defaultLbl];
[defaultLbl release];
UILabel *masterProName = [[UILabel alloc] initWithFrame:CGRectMake(28, 20, 200, 21)];
masterProName.text = [masterProjListArray objectAtIndex:i];//@"Lorem Ipusum";
masterProName.backgroundColor = [UIColor clearColor];
masterProName.textColor = [UIColor colorWithRed:51.0/255.0 green:153.0/255.0 blue:204.0/255.0 alpha:1.0];
[masterProName setFont:[UIFont fontWithName:@"Helvetica-Bold" size:17]];
masterProName.lineBreakMode = NSLineBreakByCharWrapping;
[myButton addSubview:masterProName];
[masterProName release];
UILabel *masterProID = [[UILabel alloc] initWithFrame:CGRectMake(28, 45, 200, 21)];
masterProID.text = [masterProjIDArray objectAtIndex:i];//@"133 FS";
masterProID.backgroundColor = [UIColor clearColor];
masterProID.textColor = [UIColor colorWithRed:51.0/255.0 green:51.0/255.0 blue:51.0/255.0 alpha:1.0];;
[masterProID setFont:[UIFont fontWithName:@"Helvetica" size:17]];
masterProID.lineBreakMode = NSLineBreakByCharWrapping;
[myButton addSubview:masterProID];
[masterProID release];
}
And UILabel
access method after user press the long press button
- (void)longPressTap:(UILongPressGestureRecognizer *)sender
{
if ([recognizer.view tag]) {
UILabel *view = (UILabel *)recognizer.view;
NSLog(@"---%@", view.subviews);
for (UILabel *lbl in view.subviews) {
if (recognizer.view.tag == view.tag) {
NSString *text = view.text;
NSLog(@"---%@", text);
}
}
}
}
here am putting the log
"<UIImageView: 0x75b9510; frame = (0 0; 379 100); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x75acef0>>",
"<UILabel: 0x88c4e50; frame = (28 20; 200 21); text = 'Aux Water Waste Trtmnt'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x88c49c0>>",
"<UILabel: 0x88c52f0; frame = (28 45; 200 21); text = 'M10000'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x88c5380>>",
"<UILabel: 0x88c56c0; frame = (30 70; 60 21); text = '**Default**'; clipsToBounds = YES; userInteractionEnabled = NO; tag = 1; layer = <CALayer: 0x88c5750>>",
"<UIButton: 0x88c6440; frame = (240 10; 70 80); opaque = NO; userInteractionEnabled = NO; tag = 1; layer = <CALayer: 0x88c6500>>"
In this log i want to access only "Default" text label
Please give me any suggestion on this.