iOS: Creating tip / help popups - iphone

Are there any built in, open source, or tutorials for creating a reusable easy to use popup for use with in game-help.
Essentially I would like to, on first run of a game, show popup tips / help that "point to" various on screen objects to help a user orient themselves with the game.
Update: Here is an example of how I ultimately want it to look / behave although I don't need it that generic but as close as possible would be good

I like those: https://github.com/chrismiles/CMPopTipView.
Nice and easy to set up.

Essentially what you need is a custom view.
You cannot use Apple's UIAlertView since its purpose is very different from what you are looking for.
I don't know what are your specific needs, but you may use a simple UILabel:
CGRect ref = objectToAddress.frame;
UILabel *tip = [[UILabel alloc] initWithFrame:CGRectMake(ref.x+ref.width,
ref.y+ref.height,
width,
height)];
[tip setText:messageToShow];
[self.view addSubview:tip];
[tip release];
where width and height are the dimensions of the tip you want to show and messageToShow is the message you want to display.
You can, of course, customize your UILabel as you like, changing font or background color. Check the reference for additional informations.
EDIT:
You may take a look at a possible popover implementation for iPhone: WEPopover. On the iPad you can use directly Apple's UIPopoverController

What I've done is to create two functions
- (void) showOverlay: (BOOL) show withMessage: (NSString*) message
{
if(show)
{
// I create or load a UIView with labels, etc, and with an alpha of 0.6/07
// give it a tag for later dismissal
overlay.tag = tag; // any arbitrary value
// add as subview
[self.view addSubview: overlay];
}
else
{
// hide the view
UIView *overlay = [self.view viewWithTag: tag];
[overlay removeFromSuperview];
}
}
Then I have a hide overlay function
- (void) hideOverlayInSecs: (NSInterval) time
{
[self performSelector: #selector(hideOverlay) withObject: nil afterDelay: time];
}
Then you can write a wrapper function to show / dismiss it for varying durations
[self showOverlay: YES withMessage: #"help tip"];
[self hideOverlayInSecs: 2];

In my App, the tips were fairly static, so I created an tip image using my favorite image editor, and then simply created a UIImageView with the tip image, and then added that as a subview to the current view, making sure to place it on top of other views.
It worked out pretty nicely, but again, my tips are fairly static.
If you want to display them only on the first run through, you'll need to create a BOOL that is saved in NSUserDefaults or something.

How about this?
I wrote this myself. It's pretty simple and probably what you are looking for.
Popup any UIView instance on top or bottom then disappear after a few seconds.
https://github.com/SaKKo/SKTipAlertView
Hope you find it useful. cheers,

Related

How to insert UIImageView in UITextView in the same way that iphone default message (SMS) app uses to insert multimedia content in the UITextView

I want to insert UIImageView in UITextView of Toolbar having send and camera button in the same way as iPhone default SMS app do.
You would be better off using a UIScrollView and managing UITextViews and UIImageViews in it. UITextView doesn't support adding image inline with text. In fact, it doesn't really support anything other than multiline text.
Per your comment below, there are three things I can think of to get the image as part of the text entry box:
They're not using a UITextView, but instead some custom view. That sort of thing is difficult to replicate.
They are overlaying a UIImageView over the UITextView as a subview and setting the contentInset of the UITextView so there is no overlap.
They are using a separate UIView to contain both the UITextView and UIImageView as subviews and simply arrange those subviews as needed.
Both 2 & 3 are very similar (just slightly different approaches) and probably your best approach. Personally, I think 3 is probably the best, since it give you the most control over the position of both views, but 2 should also work fine.
I agree with Aaron. Based on what I have seen, I believe the native SMS app is actually a UITableView with highly modified TableCells. The TableCells are then composite views that contain the UITextView and UIImageView as Aaron suggested.
It might be a little more work up front, but I think you will find the customization of defining your own UITableCell with the above elements will be quite useful and fall in line with the overall iOS paradigm. Things work a lot better when you work with the native paradigms than against / around them.
Cheers
I have one suggetion that try to make html file with image and text as per your requirements and load that html file into webview.
Here you can also back some particular text Bold etc.
I think nice look then textfield.
To make webview just look like simple scroll view just put this method in your code
don't forgot to write this
webView.opaque = NO;,
[self hideGradientBackground:webView]; and
- (void) hideGradientBackground:(UIView*)theView
{
for (UIView * subview in theView.subviews)
{
subview.backgroundColor = [UIColor clearColor];
if ([subview isKindOfClass:[UIImageView class]])
subview.hidden = YES;
[self hideGradientBackground:subview];
}
}
I hope this may help you.
You can implement it using UITextViewDelegate and ContentInset.
- (void)viewDidLoad
{
self.textView.delegate = self;
[self.textView addSubview:self.addedView];
[self.textView setContentInset:UIEdgeInsetsMake(0, 0, CGRectGetHeight(self.addedView.frame), 0)];
}
- (void)textViewDidChange:(UITextView *)textView
{
NSLog(#"%#",NSStringFromCGSize(textView.contentSize));
__weak typeof(self) wself = self;
[UIView animateWithDuration:0.5f animations:^{
[wself.addedView setFrame:CGRectMake(0, textView.contentSize.height + 10, CGRectGetWidth(wself.addedView.frame), CGRectGetHeight(wself.addedView.frame))];
}];
}

Using Image to Perform an Action instead of Button in iPhone Applciation

How can i use image to Perform an Action instead of Using Button or adding an image to Button, just wanna click button and perform particular set of instructions.
(Thanks in Advance)
Use a UIGestureRecogniser.
// IF your image view is called myImage
UIImageView *myImage = ...;
// Add a tap gesture recogniser
UITapGestureRecogniser *g = [[UITapGestureRecogniser alloc] initWithTarget:self action:#selector(imagePressed:)];
[myImage addGestureRecogniser:g];
[g release];
When your image is tapped, this method will get called
- (void)imagePressed:(UIGestureRecogniser *)recogniser {
NSLog(#"%#", recogniser);
}
Why don't you want to use a UIButton - it inherits from UIControl and has a lot of code that you probably don't even know exists? And it can just contain an image so it would look exactly the same?
Well, the pro about using UIButtons is that it got all touch events built right in. You can use UIImageViews, but you'll need to subclass them, while in most situations, a UIButton using a background-image would just fit.

Which UI object to do this?

I have seen many times waiting panels (panels with a uiactivityindicatorview) black/dark with some transparency and white labels.
Like this one :
I guess it is a standard element.
Where can I find it?
Try This. it's the best solution I came across to show the activity. MBProgressHUD
MBProgressHUD looks nice. You might want to check out http://code.google.com/p/toast-notifications-ios/ too.
There's no iOS component that does this.
If you don't want to include an external library just for this one component then you can do it using UI components.
/* Warning, typed from memory */
// Create the UIView that's the background
UIView *pleaseWaitView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 80)];
[pleaseWaitView setBackgroundColor:[UIColor colorWithWhite:0.5 alpha:0.5]];
[[pleaseWaitView layer] setCornerRadius:5.0f];
// And create an activity indicator
UIActivityIndicator *i = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[i startAnimating];
[pleaseWaitView addSubview:i];
[i release];
// Add it to the main view (in the middle)
[pleaseWaitView setCenter:CGPointMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2)];
[self.view addSubview:pleaseWaitView];
You can add a UILabel with whatever text you want (in your case, 'Authenticating') in the same way as you added the activity indicator.
The tricky part is setting the corner radius - you will probably need this at the top of your .m file :
#import <QuartzCore/QuartzCore.h>
NB You can do this in interface builder as well if you want (apart from the corner radius bit!) ;)
I answered a question that included an overlay like this. I included the code and the overlay image you need to do it with. Take a look at this answer and take a look at the screen shot it created. I use this overlay as I send email in the background so you will want to edit the code to do your function but the overlay code is already in place.
Locking the Fields in MFMailComposeViewController
Happy Coding!
Check out DSActivityView. I've successfully used it in a few of my projects.
As by now there is no standard UIElement for that in iOS.
But checkout this library:

UISwitch - change from on/off to yes/no

does anyone know of a way I can change the text label for on and off to yes and no.
I did it with
((UILabel *)[[[[[[switchControl subviews] lastObject] subviews] objectAtIndex:2] subviews] objectAtIndex:0]).text = #"Yes";
((UILabel *)[[[[[[switchControl subviews] lastObject] subviews] objectAtIndex:2] subviews] objectAtIndex:1]).text = #"No";
However, with the release of iOS 4.2, this is no longer supported (this probably wasn't recommended by Apple anyway)
My client is insisting on yes/no switches. I'd appreciate any advice!
many thanks
Hurrah! From iOS 6, it's possible to specify an image to be used for the on / off states, respectively. So, this can be used to display a YES / NO image (or whatever image representing the text you would prefer to use instead of the previously limited ON / OFF).
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"6.0"))
{
[mySwitch setOnImage: [UIImage imageNamed:#"UISwitch-Yes"]];
[mySwitch setOffImage:[UIImage imageNamed:#"UISwitch-No"]];
}
The images should be 77 px wide, 27 px high, and the text (one image for each state) should be horizontally centred within that 77 px width. I use transparent backgrounds for the text, so I can still make use of the tint for the background, which still works with this.
Of course, it would seem easier to just supply text, rather than having to use an image of text, but I'm certainly grateful for this new option, at least.
You need to implement your custom UISwitch for that. Or use one of already implemented :) (check this SO question and this post)
Vladimir answer is great, but in my humble opinion there is an even better implementation here: https://github.com/domesticcatsoftware/DCRoundSwitch.
Besides setting a custom text, it is easier to change the size and color of the UISwitch and you get a sharper result.
It is released under an MIT license. Have a look!
It turns out that you can create a custom UISwitch with the following items:
A UIScrollView
A UIButton
Two UILabels
A background image
A Boolean value
First you will need to add QuartzCore.framework to your project and #import <QuartzCore/QuartzCore.h> to your view controller.
Next add the UIScrollView to your view using Interface Builder. The ScrollView will be your custom UISwitch.
Next add the button and the two labels to your ScrollView. One label will be for "yes" the other for "no".
Add the image to the button and set its type to custom. This is the image I use:
Position the labels over the blue and white area of the image. Adjust the ScrollView so it is just big enough to show the blue part of the image and the thumb nob.
Add the following line to viewDidLoad:
self.mySwitch.layer.cornerRadius = 13.5;
mySwitch is the name of the ScrollView and 13.5 is half the height of the ScrollView. The above statement changes the ScrollView to have rounded ends like the UISwitch.
To make the custom switch active you will need to tie the buttons "Touch Up Inside" event to an IBAction. Here is the code I use in the event handler:
-(IBAction)mySwitchButton:(id)sender {
self.myValue = !self.myValue;
CGPoint scrollPoint = CGPointMake((self.myValue)? 43.0: 0, 0.0);
[mySwitch setContentOffset:scrollPoint animated:YES];
}
Where myValue is the boolean variable that contains the state of your switch and 43.0 is the number of points you will have to move the image over to put the switch in the off position.
That is all there is to it!
From iOS 6, it's possible to specify an image to be used for the UISwitch on / off states, but NOT the text.
This will lead trouble when internationalization is required because translators
have to provide an image text for each language, not text only.
Moreover, the size of the UISwitch image is fixed, limiting the text length.
Because of the above reasons, I like the JSWilson's answer: simple and flexible.
To relieve developers of the need to manually add the required controls, I coded a custom CRDScrollSwitch class that you can find at my GitHub repository:
https://github.com/corerd/CRDScrollSwitch

iPhone - user interaction with programmatically added UIImageView

So I'm trying to add UIImageViews programatically (in this case I don't have the option of doing it in IB) and I want to be able to refer to them and manipulate them in the -touchesBegan and -touchesMoved methods.
I've added the images like this:
UIImageView *newPiece = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:#"%d.png", [piece tag]]]];
newPiece.frame = CGRectMake(pieceX, pieceY, pieceW, pieceH);
[newPiece setCenter:CGPointMake(pieceX, pieceY)];
[newPiece setTag:[piece tag]];
[[self view] addSubview:newPiece];
[newPiece release];
And note, many of these newPiece's are added programmatically, because the method that this is in is called more than once, so the images have different centers and images and stuff, so would I need an array to hold all of them?
Thanks
NSMutableArray would probably suit your needs.
Check this very detailed post. It's precisely about handling several programatically added UIImageViews and it worked nice for me.
Create multiple views and make the touched view follow the users touch
Best luck.