logo
down
shadow

Adding a tap gesture to a UIImageView to change a UILabel?


Adding a tap gesture to a UIImageView to change a UILabel?

By : dchaitanyarao
Date : November 22 2020, 10:33 AM
may help you . I have been working on an iOS single view application in Xcode 6 for a couple days, and have hit a roadblock when I try to add touch events. Here is what I am trying to do:
code :
#import "ViewController.m"

@interface ViewController ()
{
    IBOutlet UILabel *myLabel;
    IBOutlet UIImageView *myImage;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Tapped:)];
    tap.numberOfTapsRequired = 1; //You can change this is double tap ect..
    Red.cancelsTouchesInView = YES;
    myImage.userInteractionEnabled = YES; //if you want touch on your image you'll need this
    [myImage addGestureRecognizer:tap];
}

-(void)Tapped:(UITapGestureRecognizer *)sender
{
    myLabel.text = [NSString stringWithFormat:@"It Worked"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end


Share : facebook icon twitter icon
Can a Tap Gesture Recognizer in IB be used on a UILabel and/or UIImageView

Can a Tap Gesture Recognizer in IB be used on a UILabel and/or UIImageView


By : user3768894
Date : March 29 2020, 07:55 AM
hope this fix your issue On UIImages and UILabels, userInteractionEnabled is set to NO by default. You can use a gesture recognizer with both of them, but first you have to reset this property.
In Interface Builder or Storyboard, on the label or the image, check the box for userInteractionEnabled.
code :
myLabel.userInteractionEnabled = YES;
myImage.userInteractionEnabled = YES;
myLabel.userInteractionEnabled = true
myImage.userInteractionEnabled = true
Adding gesture recognizer to UIImage, not UIImageView

Adding gesture recognizer to UIImage, not UIImageView


By : user3829863
Date : March 29 2020, 07:55 AM
should help you out As UIImage extends from NSObject you can not add UITapGestureRecognizer to it, you have to add gesture to the UIImageView itself. Then in any of the UIGestureRecognizer delegate methods:
code :
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer;
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;
bool CGRectContainsPoint ( CGRect rect, CGPoint point );
when I am adding Long Press Gesture on uiimageview in Table View Cell .Uiimageview Is not showing With correct Image

when I am adding Long Press Gesture on uiimageview in Table View Cell .Uiimageview Is not showing With correct Image


By : gyadi gyadi
Date : March 29 2020, 07:55 AM
hope this fix your issue You need to get indexpath using view's hierarchy and use this indexpath instead of its tag value .
code :
UIImageView *view_ =(UIImageView*) sender.view
UITableViewCell *cell = (UITableViewCell *)view_.superview.superview;
NSIndexPath *indexPath = [recipeCollectionView indexPathForCell:cell];
Profile_PopUPVc.ImageUrl=[[arrResultData valueForKey:@"picture"]objectAtIndex:indexPath.row];
Adding UILabel to UIImageView

Adding UILabel to UIImageView


By : michael
Date : March 29 2020, 07:55 AM
it should still fix some issue UIImageView is a subclass of UIView so you can add any UI object onto it.
App crashes after adding gesture UITapGestureRecognizer to UILabel

App crashes after adding gesture UITapGestureRecognizer to UILabel


By : Ksen'Mih
Date : March 29 2020, 07:55 AM
it should still fix some issue I guess you are passing the target wrong. just pass self instead of self.selectionHeaderLabel.
Then, code will be like this :
Related Posts Related Posts :
  • CordovaError: Promise rejected with non-error: Error code 65
  • How to append NSMutable strings into a UILabel
  • CustomCell label value does not change
  • Display ad in iAd Bannerview iAd Network
  • Warning: "Could not get traitsetID for iPhone11,6" (Assets.xcassets)
  • Changing root view controller after iOS app has loaded.
  • SocketRocket and iOS certificate pinning
  • Draggable UIButton Snap To a Circle Path
  • Running FireBase in the background
  • resizing UIPopoverController to fit UITableController
  • UICollectionView Exception Crash
  • targeting iOS5 - will it work on iOS6 also?
  • FBLoginView get email
  • Scale UIImages height to UIImageView height
  • Creating a custom progress indicator in ios
  • NSRunLoop API difference
  • Is it possible to inject custom settings into my iOS application "Notifications" settings dialog?
  • UIAlertview not accepting string as message
  • Axis change of stackView giving layout error
  • How to use AVAssetResourceLoader?
  • How to write block definition using properties?
  • iOS connect/reconnect to Bluetooth device when using external-accessory and MFi
  • Saving XMPP Multi User chat messages through XMPP MessageArchiving in iOS
  • Deciding iOS version: pros and cons
  • iOS: Resigned app cannot access keychain through security API
  • How can I set To and Subject fields in an E-Mail being sent by UIDocumentInteractionController?
  • Updating uilabel in view controller underneath another
  • Maximum time Intervel for NSTimer
  • Delete Core Data Entry from Table View Controller
  • How to unload UIViewcontroller from memory?
  • Compressing UIImage as Far as Possible?
  • Optimizing workflow to update internally owned cocoapods dependencies?
  • Formatting an NSDate with Abbreviated Month/Day Names
  • I'm creating a quiz game with 4 answers and I want to add score
  • Tap Gesture to Hide Navigation Bar, Tab Bar, and Status Bar
  • FBSessionStateClosedLoginFailed when I am logged in through Settings
  • CGRect positioning according to center point
  • iOS: Update table view datasource with animations without core data
  • iOS : Where to start for AliPay integration?
  • Routing App Coverage File missing but not needed?
  • Drawing on a zoomable view
  • Append NSStrings and NSNumber to NSMutableArrays and make NSMutable dictionary
  • Terminating app due to uncaught exception 'NSRangeException' when calling dequeueReusableCellWithReuseIdentifier:forInde
  • Collision without physics (Cocos2D + Box2D iOS)
  • Creating a percentage based iOS layout
  • Update tableView row from AppDelegate Swift 4
  • Assigning return value of a class method to a variable error
  • how to display circular progress in delphi ios apps?
  • I can't figure how to fix this Expected identifier or '('
  • How to Test APIs in Swift 4?
  • Link error /Build/Products/Debug-iphonesimulator file not found
  • working with a very large JSON object in iOS
  • Turn off part of the iPhone Screen
  • Phonegap 3.0 app with facebook login using xCode
  • How to add interstitial admob ads to my ios project
  • adding tapku calendar to ios app
  • Add an alertcontroller in a global swift file?
  • Take square image with Cordova (Phonegap) Camera API?
  • Amazon S3 policy allowing only upload not overwrite
  • How to change the UILabel content by tapping?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org