UILabel *traking = [[UILabel alloc] initWithFrame:CGRectMake(8, y, SCREEN_WIDTH-4, 20)];
[traking setTextColor:[UIColor redColor]];
[traking setBackgroundColor:[UIColor clearColor]];
[traking setFont:[UIFont fontWithName: @"Trebuchet MS" size: 16.0f]];
NSString *trakingText = [NSString stringWithFormat:@"Tracking Number : %@",dict[@"shipping_number"][@"text"]];
[traking setText:trakingText];
traking.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(textTapped:)];
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(textPressed:)];
[traking addGestureRecognizer:tap];
[traking addGestureRecognizer:longPress];
[myOrdersScrollView addSubview:traking];
- (void) textPressed:(UILongPressGestureRecognizer *) gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateRecognized &&
[gestureRecognizer.view isKindOfClass:[UILabel class]]) {
UILabel *someLabel = (UILabel *)gestureRecognizer.view;
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
[pasteboard setString:someLabel.text];
//let the user know you copied the text to the pasteboard and they can no paste it somewhere else
}
}
- (void) textTapped:(UITapGestureRecognizer *) gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateRecognized &&
[gestureRecognizer.view isKindOfClass:[UILabel class]]) {
NSLog(@"fjeeddfj");
UILabel *someLabel = (UILabel *)gestureRecognizer.view;
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
[pasteboard setString:someLabel.text];
//let the user know you copied the text to the pasteboard and they can no paste it somewhere else
}
}
Be the first to comment.