UIImageView as a link to a URL - iphone

How to make a UIImageView open a URL in Safari when user clicks it?

I would suggest using a button for this purpose instead. You can create a custom UIButton with whatever image you want. This gives the advantage of providing the built-in target-action mechanism of a button, as well as being able to provided a highlighted image to provide the user feedback. Consider using something like this:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:#"regular_image.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:#"highlighted_image.png"] forState:UIControlStateHighlighted];
[button addTarget:self action:#selector(loadURL) forControlEvents:UIControlEventTouchUpInside];
Note that it will still look like "just an image" to the user.

Related

How to enable touchesMoved() with button action?

I am doing one piano application. There i am using button action to play music. But its not supporting drag functionalities. I have used touchesMoved(),touchBegan() methods also . But nothigh is working.Can anyone help me, please?
Button supports drag functionality. You should add your target by below control events.
[button addTarget:target action:#selector(action1) forControlEvents:UIControlEventTouchDragInside];
[button addTarget:target action:#selector(action2) forControlEvents:UIControlEventTouchDragOutside];
[button addTarget:target action:#selector(action3) forControlEvents:UIControlEventTouchDragExit];
[button addTarget:target action:#selector(action4) forControlEvents:UIControlEventTouchDragEnter];
Implement proper actions for each event and it should identify proper drag event.

How to remove the greyed out look of a disbled UIButton

I've got a UIButton that i want to look exactly the same when it's in its disabled state as when it's in its Normal state. Right now it has a slight greyed out look to it.
Do not use enabled property or setEnabled:NO method, instead use:
[myButton setUserInteractionEnabled:NO];
That would prevent the button for being touched, but without changing his looks!
The other way is if your button is a custom button and has an image:
[button setImage:someImage forState:UIControlStateNormal];
[button setImage:someImage forState:UIControlStateDisabled];
[button setEnabled:NO];

Create IBOutlet and connection with code

I am creating an iPad application that behaves like a power point presentational. I am creating several slides and each slides contains several images with basic functionality. Because I am creating so many slides it will be nice if I can create the IBOutles programmatically since I place so many buttons per slide for instance. it takes a while to place those outlets and create the connections. How can I speed up this process?
Why not just create every item programmatically?
Take a UIButton for example.
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:#selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:#"Hello" forState:UIControlStateNormal];
button.frame = CGRectMake(40.0, 200.0, 170.0, 40.0);
[self.view addSubview:button];
This should be of interest to you: http://developer.apple.com/library/ios/#documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/030-Edit_User_Interfaces/edit_user_interface.html#//apple_ref/doc/uid/TP40010215-CH6-SW1
There's even a nice video tutorial if you click: "To create and connect a new outlet ..."
Good luck!

iphone: unable to change background of buttons

I have a situation I'm trying to change background image of 4 buttons like this:
if(some condition){
[firstSeverityButton setBackgroundImage:[UIImage imageNamed:#"greySeverity.jpg"] forState:UIControlStateDisabled];
[secondSeverityButton setBackgroundImage:[UIImage imageNamed:#"greySeverity.jpg"] forState:UIControlStateNormal];
[thirdSeverityButton setBackgroundImage:[UIImage imageNamed:#"greySeverity.jpg"] forState:UIControlStateNormal];
[fourthSeverityButton setBackgroundImage:[UIImage imageNamed:#"greySeverity.jpg"] forState:UIControlStateNormal];
[fifthSeverityButton setBackgroundImage:[UIImage imageNamed:#"redSeverity.png"] forState:UIControlStateNormal];
}
But the background of the other four disappears when I touch any one
Please enlighten me on this how can his be tackled.
May be you are looking for the radiobutton, You can write down a custom class for radio button and make things work out easily.
[firstSeverityButton setBackgroundImage:[UIImage imageNamed:#"greySeverity.jpg"] forState:UIControlStateDisabled];
This code actually works fine, with every control state. I think the problem is with the initial image for the button and the current button state (in both nib and code).
The state of buttons can be changed with:
button.enabled=yes;
button.highlighted = NO;
button.selected = NO;
When you setup image for control state specifically, the change on image appear on that specific control state. So the change depends on both the initial image and the current control state of button
NOTE: We are applying change on the background image. There is an image property for the button which can actually hide the changes of background image. If you setup the image
[firstSeverityButton setImage:[UIImage imageNamed:#"greySeverity.jpg"] forState:UIControlStateDisabled];
anywhere in code and maybe it can hide your background image setting.
Also there is a possibility of error in your if-else loop ...go through the loops and verify every conditions whether the images get set properly.

How is a UIButton's image set programmatically?

How does one set the image of a UIButton from within the code?
I try the following but it just leaves the button as a white square.
[A1 setImage:[UIImage imageNamed:[NSString stringWithFormat:#"m1.10001.png"]] forState:UIControlStateNormal];
Your image construction seems a bit overly complicated, but it should work. Don't forget to use the correct button type (custom):
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:#"m1.10001.png"] forState:UIControlStateNormal];
With newer SDKs you can omit the .png. Make sure that the image actually exists (you can store it in a temporary variable and check for nil, for example).
And of course make sure that the button exists (or is bound), i.e. non-nil, when setting the image.