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 04-21-2008, 11:50 AM   #1 (permalink)
Registered Member
 
Join Date: Apr 2008
Posts: 7
Senly is an unknown quantity at this point
Default UIColor with background view

Hi everyone i was wondering if whe could change the color of an UIView by clicing a button i a m able to do this with a label but not with a background view hel please

senly
Senly is offline   Reply With Quote
Old 04-21-2008, 12:34 PM   #2 (permalink)
New Member
 
Join Date: Apr 2008
Location: Lexington, KY
Posts: 108
Fastrak is an unknown quantity at this point
Default Re: UIColor with background view

-(void)buttonPressedUIButton *)button
{
[self.view setBackgroundColor:[UIColor redColor]];
}

//this code assumes you are using a view controller
Fastrak is offline   Reply With Quote
Old 04-22-2008, 03:00 AM   #3 (permalink)
Registered Member
 
Join Date: Apr 2008
Posts: 7
Senly is an unknown quantity at this point
Default Re: UIColor with background view

ok i wanted to do a changing background app i did this in the MyvIew.h file

@interface MyView : UIView
{
IBOutlet UIView *color;
}
-(IBAction)Lightid)sender;
-(IBAction)Darkid)sender;
@end

and this in the MyViem.m file

@implementation MyView
-(IBAction)lumiereid)sender
{
[self.view setBackgroundColor:[UIColor whiteColor]];
}
-(IBAction)ombreid)sender
{
[self.view setBackgroundColor:[UIColor blackColor]];
}
@end


like you told me, i made 2buttons and 1 View and i connect them but wen i build it says

error:request for member 'view'in something not a structure or union ...


help please
Senly is offline   Reply With Quote
Old 04-22-2008, 08:59 AM   #4 (permalink)
New Member
 
Join Date: Apr 2008
Location: Lexington, KY
Posts: 108
Fastrak is an unknown quantity at this point
Default Re: UIColor with background view

I have found too many problems with the interface builder and just code things manually.

simpleAppDelegate.h
Code:
//
//  simpleAppDelegate.h

#import <UIKit/UIKit.h>

@class MyView;

@interface simpleAppDelegate : NSObject {
	IBOutlet UIWindow *window;
	IBOutlet MyView *contentView;
}

@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) MyView *contentView;

@end
simpleAppDelegate.m
Code:
//
//  simpleAppDelegate.m

#import "simpleAppDelegate.h"
#import "MyView.h"

@implementation simpleAppDelegate

@synthesize window;
@synthesize contentView;


- (void)applicationDidFinishLaunching:(UIApplication *)application {	
     window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
     contentView = [[MyView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
     [window addSubview:contentView];


	[window makeKeyAndVisible];
}


- (void)dealloc {
	[contentView release];
	[window release];
	[super dealloc];
}

@end
MyView.h
Code:
//
//  MyView.h

#import <UIKit/UIKit.h>

@interface MyView : UIView {
UIButton *blackButton;
UIButton *whiteButton;
}

@end

MyView.m
Code:
//
//  MyView.m


#import "MyView.h"


@implementation MyView


- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Initialization code.
	[self setBackgroundColor:[UIColor cyanColor]];
		

		
    //add a Black button
    blackButton = [[UIButton buttonWithType:UIButtonTypeGlass] retain];
    [blackButton setFrame:CGRectMake((self.bounds.size.width - 100.0) / 2.0,100.0, 100.0, 40.0)];
    [blackButton setTitle:@"BLACK" forStates:UIControlStateNormal];
	[blackButton setBackgroundColor:[UIColor clearColor]];
    [blackButton setTintColor:[UIColor blackColor]];
	[blackButton addTarget:self action: @selector(turnBlack:) forControlEvents:UIControlEventTouchUpInside];
	[self addSubview:blackButton];
	
	 //add a White button
    whiteButton = [[UIButton buttonWithType:UIButtonTypeGlass] retain];
    [whiteButton setFrame:CGRectMake((self.bounds.size.width - 100.0) / 2.0,200.0, 100.0, 40.0)];
    [whiteButton setTitle:@"WHITE" forStates:UIControlStateNormal];
	[whiteButton setBackgroundColor:[UIColor clearColor]];
    [whiteButton setTintColor:[UIColor whiteColor]];
	[whiteButton addTarget:self action: @selector(turnWhite:) forControlEvents:UIControlEventTouchUpInside];
	[self addSubview:whiteButton];

    }
    return self;
}

-(void) turnBlack:(id)sender
{
[self setBackgroundColor: [UIColor blackColor]];
}

-(void) turnWhite:(id)sender
{
[self setBackgroundColor: [UIColor whiteColor]];
}





- (void)drawRect:(CGRect)rect {
    // Drawing code.
}


- (void)dealloc {
  [blackButton release];
  [whiteButton release];
  [super dealloc];
}

@end
Fastrak 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


Similar Threads
Thread Thread Starter Forum Replies Last Post
UILabel background color mademo iPhone SDK Development 3 02-10-2010 09:04 AM
Default TableView section header background color jonc iPhone SDK Development 4 01-03-2009 11:18 PM
how to make ur application to run in background i.d3v1l iPhone SDK Development 23 09-09-2008 07:57 AM
Launching app with data without background services? bonehead iPhone SDK Development 5 04-23-2008 02:51 PM


» Advertisements
» Online Users: 402
15 members and 387 guests
13dario13, 7twenty7, buggen, eski, EvilElf, glenn_sayers, j.b.rajesh@gmail.com, LunarMoon, morterbaher, n00b, QuantumDoja, sacha1996, Sami Gh, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,673
Threads: 94,122
Posts: 402,906
Top Poster: BrianSlick (7,990)
Welcome to our newest member, morterbaher
Powered by vBadvanced CMPS v3.1.0

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