MBProgressHUD tap to cancel, longer text? - iphone

I'd like to use MBProgressHUD (or similar look) as alternative to default UIAlertView.
I need a canceling capability on this view.
I tried adding the following method to MBProgressHUD class but it didn't get called when touched.
Any idea?
(void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*)event
I can't use gesture recognizer since my lowest target version is 3.1.2.
Also, it seems complex to enlarge label size for MBProgressHUD's text.
Are there altanatives than fixing MBProgessHUD for the purpose?

I just had quick look at MBProgressHUD and would use that. First, change the size of the HUD by modifying layoutSubviews in MBProgressHUD.h. I would then create a new button class (UIButton subclass) and add this as a subview of the HUD.

This is a super old thread, but it would be way easier just to set hud's UserInteractionEnabled:YES and add a tapGestureRecognizer to it.
Cheers.

Related

CCMenuItem doesn't respond subclassing and adding cctouch methods to CCMenu

I'm making a menu, and I want one of the buttons to respond when user touch it down, so I made a subclass of CCMenu in order to add cctouchbegan method And manage it there.
The problem is that I can make it to respond both things (menuItem & cctouch), is this normal?
is there a way to force it to do both things?
Thank you in advance, let me know if you need me to put some of the code here
You should look at CCMenu.m -- it already implements ccTouchBegan and sets a selected flag on CCMenuItems. Your approach is probably not working because you're stealing the messages from your parent class.
Your subclass should call [super ccTouchBegan...] first, then check the selected state of the CCMenuItems to determine which button to change visually.
EDIT:
Or, even easier! -- Subclass the appropriate CCMenuItem subclass (e.g. CCMenuItemSprite) and overload the selected method from it's default to include your visual alterations:
-(void) selected
{
[super selected];
//call method to update visuals here
}
You can simple create your own CCLayer subclass, set it's isTouchEnabled property to YES and implement any touch logic you want

Custom UIAlertView?

Seeing as the blue doesn't go with my UI interface, im just wondering if there is a way to change the colour of the uialertview, or use a image instead. With all the buttons, 'dismiss' etc still there
Thanks
The fine folks at CodeCropper just put out an open-source control that lets you create custom alert views. It's awesome.
https://github.com/gpambrozio/BlockAlertsAnd-ActionSheets
You could try presenting a Modal View Controller with a transparent background.
ModalViewController *popupController = [[ModalViewController alloc] initWithNibName:#"ModalViewController" bundle:nil];
[self presentModalViewController:popupController animated:NO];
Something like this for the ModalView (http://stackoverflow.com/questions/849458/transparent-modal-view-on-navigation-controller)
This way you can create a custom Alert, but it's really a modal view that you can customize
You can either go through its subviews and change what you need to change, or subclass it. Because UIAlertView inherits from UIView you can use:
myAlertView.subViews
and modify the views or subclass UIAlertView to create your custom AlertView. Here is a very good article on how to sublass UIAlertView to get whatever design/color you want.
Subclassing UIAlertView
Basically what you want to override is this method:
- (void) drawRect:(CGRect)rect
Hope that helps.
you can use a uiview instead of uialertview and can easily customize uiview according to your needs
You could use CODialog. It's fully style-able and configurable.
Subclassing UIAlertView is not an option, this class is not intended to be subclassed and doing so might be a reason of app rejection.
Instead, you might try to go through all alert view's subviews or create your own class
In case you are going to create your own class, here's an example of how to fake UIAlertView:
http://iosdevtricks.blogspot.com/2013/04/creating-custom-alert-view-for-iphone.html
If looking for custom alert view then it might help.
https://github.com/Pradeepkn/PKCustomAlertView/
Hope it helps some one.
No need of setting delegate. You will get call back once the action completes on same method.
Enjoy :)
Custom Alert view
Table Alert view

Does UITextField consume touch events?

My view controller has UITextField object as a subview. The controller is set as target to handle the text field's UIControlEventTouchUpOutside event.
I'm trying to use this event handler for dismissing keyboard when the text field becomes first responder, but it seems to be never called. Delegate methods like textFieldShouldReturn work just fine.
Why the text field object doesn't send action message to the target? I tried this scheme for bunch of all touch events, but no luck.. Or do I have to subclass UITextField somehow to be able to catch this event?
Thanks in advance!
UITextField for sure responds to those event to handle cursor positioning and so on. It might not 'forward' those event to its parent. If you need to intercept those, you can subclass UITextEvent and catch those event yourself (of course do not forget to call [super blablabla] in order to keep the standard behavior.
Maybe It just doesn't respond the UIControlEventTouchUpOutside event. I am sure it will respond UIControlEventValueChanged event. I think you can put a transparent custom UIButtom as background view, and if any touchInSideUp in the UIButtom, you can dismissing keyboard as desired.
It responds to the same events as UIButton. Take a look in IB. Also you may consider using UITextFieldDelegate method
- (BOOL) textFieldShouldBeginEditing:(UITextField *)textField

How can I find out when a pinch gesture is finished (UIGestureRecognizer)

I want to get a callback when my UIPinchGestureRecognizer finished a pinch-gesture. Moreover it would be great to know if the finished gesture was a zoom in or a zoom out.
Does anyone know a method to use? Or the approach to do?
Thanks!
Another approach instead of overriding touchesEnded:, is that you could just check the state of the gesture recognizer in your target handler method.
-(void)handlePinchGesture:(UIGestureRecognizer*)gestureRecognizer {
if(UIGestureRecognizerStateEnded == [gestureRecognizer state]){
// do something
}
}
You can know if it was a zoom in or out by the scale property of the UIPinchGestureRecognizer.
Just overrride it's touchesEnded: method to get a callback (and the call some other method if you wish).
The best approach which does not require subclassing is to examine the "state" property on the gesture recognized instance in your action handler. The state will change during all phases of the lifecycle of the gesture. The state change you're looking for is UIGestureRecognizerStateEnded. It is also good practice to check for UIGestureRecognizerStateCancelled as well.

Objective-C/iPhone: Windows' view not responding to button clicks!

So in my app delegate I add a call add the myViewController.view to the main window:
1. [window addSubview:myViewController.view];
In myViewController I do the following code in the viewDidAppear method:
2. [self presentModalViewController: yourViewController animated: YES];
In my yourViewController class I do the following to try and go back to the main window
3. [self dismissModalViewControllerAnimated:YES];
My main windows view appears with buttons in all, but the buttons won't react to any click or anything. It's like there is something over them that I can't see.
Also, the main windows button works before this process but doesn't after the process.
Any help would be appreciated.
If the dismiss method call is in the modal view controller (not the parent that presents it), then you actually want to call [self.parentController dismissModalViewControllerAnimated:YES];
There are a number of reasons why things might not be responding to your touches. Here are two that have happened to me:
The frame of the view you want to touch is too small. UIViews can draw outside of their frames, so it might look ok, but not respond if the touch is technically outside of the frame -- you also have to check that all the superview's up the hierarchy also have a large enough frame.
If anything in your view is a UIImageView or child thereof, it won't respond to user touches because UIImageView has userInteractionEnabled set to NO by default. You can fix this just by setting myImageView.userInteractionEnabled = YES;
Edit: Oli pointed out in the comments that dismissModalViewControllerAnimated: should work if called on either self.parentController or simply self, since that method is smart enough to call the parent if needed, according to the docs. The docs also make it sound like this might behave differently if you have multiple model views open at once, though, so I would still consider it cleaner code to call the method on self.parentController directly.