UIButton Touch and Hold

You can do the following: Make an NSTimer that will start up when the app starts or in viewDidLoad and also make a boolean. For example: //Declare the timer, boolean and the needed IBActions in interface. @interface className { NSTimer * timer; bool g; } -(IBAction)theTouchDown(id)sender; -(IBAction)theTouchUpInside(id)sender; -(IBAction)theTouchUpOutside(id)sender; //Give the timer properties. @property (nonatomic, retain) … Read more

Sizing a UILabel to fit?

I had to do this enough that I extended UILabel to do it for me: @interface UILabel (BPExtensions) – (void)sizeToFitFixedWidth:(CGFloat)fixedWidth; @end @implementation UILabel (BPExtensions) – (void)sizeToFitFixedWidth:(CGFloat)fixedWidth { self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, fixedWidth, 0); self.lineBreakMode = NSLineBreakByWordWrapping; self.numberOfLines = 0; [self sizeToFit]; } @end then to have a label to have a variable multiline height but … Read more

Fix warning “Capturing [an object] strongly in this block is likely to lead to a retain cycle” in ARC-enabled code

Replying to myself: My understanding of the documentation says that using keyword block and setting the variable to nil after using it inside the block should be ok, but it still shows the warning. __block ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:… [request setCompletionBlock:^{ NSDictionary *jsonDictionary = [[CJSONDeserializer deserializer] deserialize:request.responseData error:nil]; request = nil; // …. … Read more

What are best practices for validating email addresses on iOS 2.0

The answer to Using a regular expression to validate an email address explains in great detail that the grammar specified in RFC 5322 is too complicated for primitive regular expressions. I recommend a real parser approach like MKEmailAddress. As quick regular expressions solution see this modification of DHValidation: – (BOOL) validateEmail: (NSString *) candidate { … Read more

How to zoom in/out an UIImage object when user pinches screen?

As others described, the easiest solution is to put your UIImageView into a UIScrollView. I did this in the Interface Builder .xib file. In viewDidLoad, set the following variables. Set your controller to be a UIScrollViewDelegate. – (void)viewDidLoad { [super viewDidLoad]; self.scrollView.minimumZoomScale = 0.5; self.scrollView.maximumZoomScale = 6.0; self.scrollView.contentSize = self.imageView.frame.size; self.scrollView.delegate = self; } You … Read more