iphone sdk- UIAlertView button with image - iphone

can you please tell me if it is possible to use an uiimage view as uialertview button "text"?
i was unable to find the answer googling..
thanks a lot

Yes, it is possible, but I wouldn't recommend it. You'd have to run through the UIAlertView's subviews until you find one that is of the right class, I would assume UIButton, and add your UIImageView on top like this:
for (UIView *v in [myAlertView subviews]) {
if ([v isKindOfClass:[UIButton class]]) {
//IF I AM THE RIGHT BUTTON
[v addSubview:myUIImageView];
}
}
To determine the correct button, you might initially give it some odd text like "foobar5" and test each button to see if that is its text, and if so, remove the text and add the UIImageView.

You can use unicode characters, which are rendered as icons.
I described it here:
Adding Images to UIActionSheet buttons as in UIDocumentInteractionController

Related

UITextfield at UISearchbar appears different at simulator and on actual iPhone

I managed to customize the look and feel of the UITextfield at UISearchBar using the code below:
for (UIView *subview in [searchBar subviews])
{
if ([subview isKindOfClass:NSClassFromString(#"UISearchBarTextField")]){
[(UITextField *)subview setBackground:[UIImage imageNamed:#"background_searchField.png"]];
[(UITextField *)subview setTextColor:[UIColor redColor]];
}
}
It appears exactly what I wanted when I use the simulator. However, when I tested it on an actual iPhone, the background image was not visible.
Please advice. Many thanks.
Do you have the same exact version of iOS on both simulator and device?
Anyway, don't use this black magic, the UISearchFiled is highly customizable through UIAppearance protocol, check "Customizing Appearance" section in reference.
Same goes for UITextField, you can override text color and background using properties, and do more complicated customization in "Drawing and Positioning Overrides"

Is there any other style presenting an UIAlertView?

I saw one app in which the notification/alert view was coming from the top of the iphone screen with gradient black color.
May I have details about alert/notification styles if any?
you may use this link ... maybe it will help you. one other way is to use UIActionsheet.
http://joris.kluivers.nl/blog/2009/04/23/subclass-uialertview-to-create-a-custom-alert/
There's the UIActionSheet—but it is raises from the bottom.
Unfortunately not. And customize the original UIAlertView is a trick, that acts on subviews hierarchies. you can sub class it and change it's background color overriding the drawRect: method and removing the original background with those lines of code
- (void)didAddSubview:(UIView *)subview {
if ([subview isMemberOfClass:[UIImageView class]]) {
[subview removeFromSuperview];
}
}
But it is a trick and it could be lost in future release of iOS

When using a SearchBarDisplay, how to change name of the cancel button

When setting a SearchBarDisplay, using IB or programmatically it gets a Cancel button right to the search window. The text on the button says "Cancel". How do I change text to another language.
I know how to change text for a Done button at the Navbar using only SearchWindow but that does not seem to work for this button which comes as default.
And a similar question is the text "No result" coming up in the table if no match.
How change to another language?
You can change title of you cancel but of searchBar by this :
for (UIButton *v in srchBar.subviews)
{
NSLog(#"%#",v);
if ([v isKindOfClass:[UIButton class]])
{
[v setTitle:#"Hello" forState:UIControlStateNormal];
}
}
now set this title as per your language.
i tried this and its working in my demo app.
let me know if it wont work for you.

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.

How to add a HUD? (iOS)

I am trying to have some controls appear when you push a button and have it disappear when you press a different button. Right now the HUD is comprised of an image view, and some custom buttons in a UIView called "credits". I've managed to have it disappear using:
[credits removeFromSuperview];
How do I have it reappear?
If it's just a UIImageView, you should...
[self.view addSubview:credits];
... assuming you've not released it already. On a side note, there is a really good HUD for iOS here: http://github.com/matej/MBProgressHUD
I believe you can just set the view to be hidden
[self.view setHidden:YES];
While it's hidden, you can also update the view and then show again
[self.view setHidden:NO];
You'd better set their hidden property to whether YES or NO
This method will toggle the UIView credits hidden property
- (void) toggleCredits {
[credits setHidden:![credits isHidden]];
}