Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-08-2010, 10:18 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Amsterdam, The Netherlands
Posts: 782
TUX2K is on a distinguished road
Default Custom UIButton which wil show and hides an image

I'm stuck on the following code.
Some how my UIButton Extended class cant show or hide an UIImageView

My methods are being called and the imageview is not nil.

Here is the code:
Code:
@interface UILinkedImageButton : UIButton {
	IBOutlet UIImageView *linkImageView;
}

@property (nonatomic, retain) IBOutlet UIImageView *linkImageView;

@end
Code:
#import "UILinkedImageButton.h"

@interface UILinkedImageButton ()
- (void)showImage;
- (void)hideImage;
@end


@implementation UILinkedImageButton


@synthesize linkImageView;

- (void) dealloc{
	
	[linkImageView release], linkImageView = nil;
	[super dealloc];
}

- (id) initWithCoder:(NSCoder *)aDecoder
{
	self = [super initWithCoder:aDecoder];
	
	if(self){
		[self addTarget:self action:@selector(showImage) forControlEvents:UIControlEventTouchDown];
		[self addTarget:self action:@selector(hideImage) forControlEvents:UIControlEventTouchUpInside];
		[self addTarget:self action:@selector(hideImage) forControlEvents:UIControlEventTouchUpOutside];
	}
	
	return self;
}

- (void)showImage
{
	if(self.imageView){
		NSLog(@"UILinkImageButton - showImage - currentStatus: %@", self.imageView);
		self.imageView.hidden = NO;
		[self.superview layoutIfNeeded];
	}	
}

- (void)hideImage
{
	if(self.imageView){
		NSLog(@"UILinkImageButton - hideImage");
		self.imageView.hidden = YES;
	}
}

@end
TUX2K is offline   Reply With Quote
Old 07-08-2010, 10:32 AM   #2 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 577
Speed is on a distinguished road
Default

Instead of .hidden, try use:

Code:
imageView.alpha = 0.0;
You can also fade with this in an animation. If you want to show the image, increase the alpha to 1.0.
Speed is offline   Reply With Quote
Old 07-09-2010, 02:17 AM   #3 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Amsterdam, The Netherlands
Posts: 782
TUX2K is on a distinguished road
Default

Quote:
Originally Posted by Speed View Post
Instead of .hidden, try use:

Code:
imageView.alpha = 0.0;
You can also fade with this in an animation. If you want to show the image, increase the alpha to 1.0.
Tried that, still the images won't show. if I move all the methods to the view controller it all works.

But there are many buttons so a class like this would really help.
Anyone any suggestions?

Last edited by TUX2K; 07-09-2010 at 02:25 AM.
TUX2K is offline   Reply With Quote
Old 07-09-2010, 06:43 AM   #4 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 43
ashishjraval is on a distinguished road
Default

Quote:
Originally Posted by TUX2K View Post
I'm stuck on the following code.
Some how my UIButton Extended class cant show or hide an UIImageView

My methods are being called and the imageview is not nil.

Here is the code:
Code:
@interface UILinkedImageButton : UIButton {
	IBOutlet UIImageView *linkImageView;
}

@property (nonatomic, retain) IBOutlet UIImageView *linkImageView;

@end
Code:
#import "UILinkedImageButton.h"

@interface UILinkedImageButton ()
- (void)showImage;
- (void)hideImage;
@end


@implementation UILinkedImageButton


@synthesize linkImageView;

- (void) dealloc{
	
	[linkImageView release], linkImageView = nil;
	[super dealloc];
}

- (id) initWithCoder:(NSCoder *)aDecoder
{
	self = [super initWithCoder:aDecoder];
	
	if(self){
		[self addTarget:self action:@selector(showImage) forControlEvents:UIControlEventTouchDown];
		[self addTarget:self action:@selector(hideImage) forControlEvents:UIControlEventTouchUpInside];
		[self addTarget:self action:@selector(hideImage) forControlEvents:UIControlEventTouchUpOutside];
	}
	
	return self;
}

- (void)showImage
{
	if(self.imageView){
		NSLog(@"UILinkImageButton - showImage - currentStatus: %@", self.imageView);
		self.imageView.hidden = NO;
		[self.superview layoutIfNeeded];
	}	
}

- (void)hideImage
{
	if(self.imageView){
		NSLog(@"UILinkImageButton - hideImage");
		self.imageView.hidden = YES;
	}
}

@end

Instead of self.imageView.hidden = YES; you can try this code imageView.hidden = TRUE;
when you want to show it then you can write imageView.hidden = FALSE;

I think you get it
.....
ashishjraval is offline   Reply With Quote
Old 07-09-2010, 07:02 AM   #5 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Amsterdam, The Netherlands
Posts: 782
TUX2K is on a distinguished road
Default

That still won't make it work !
TUX2K is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 344
12 members and 332 guests
akacaj, cgokey, esoteric, EXOPTENDAELAX, GHuebner, HemiMG, Mirotion22, mjnafjke, Pudding, SLIC, Sloshmonster, Sonuye857
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,652
Threads: 94,115
Posts: 402,887
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Sonuye857
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:23 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0