2

I want to add image as button, and when it is clicked it should open a new view controller... Does anyone know how to do?

I created a button and added image, but its not nice, because when I click on the image it animates a square arround the image, which I do not want. This what I did.

- (void)setTutorialButtonImage
{
    [self.tutorialButton setImage:[UIImage imageNamed:@"app_logo.png"] forState:UIControlStateNormal];
}

Does any one know how to do... just an image and when I click on it start a new controller

3
  • It's the way you did... How was the button presented? Did you set it as UIButtonTypeCUstom? Commented Mar 11, 2013 at 15:09
  • you could just put an image with a blank button above it Commented Mar 11, 2013 at 15:10
  • just do UIButton with custom style, do set adjustsImageWhenHighlighted to NO and maybe use touch down control event instead of touch up Commented Mar 11, 2013 at 15:11

3 Answers 3

2

You can disable the highlighting effect by using

self.tutorialButton.adjustsImageWhenHighlighted = NO;
Sign up to request clarification or add additional context in comments.

Comments

0

Also try setting the same image for selected and highlighted states too

[button setBackgroundImage:[UIImage imageNamed:@"app_logo.png"] forState: UIControlStateHighlighted];
[button setBackgroundImage:[UIImage imageNamed:@"app_logo.png"] forState: UIControlStateSelected];

For better look and feel you can apply insets on image using

- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets

Comments

0
UIButton *sampleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[sampleButton setFrame:CGRectMake(x, y, width, height)];
[sampleButton setBackgroundImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];
[sampleButton addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:sampleButton];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.