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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 04-30-2008, 03:47 PM   #1 (permalink)
ddavtian
New Member
 
Join Date: Apr 2008
Posts: 10
Default UIButton with an image

Ok I have been at this for a few hours now and it is starting to bug me a little bit, I am trying to create a UIButton with a UIImage associated to it, here's what I got. After I build and go, I see the button is there, but no image...any ideas? I have dropped the image into the project, so it's there

- (void)loadView {

// create an instance of UIView
UIView *myView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];

[myView setAutoresizingMask:UIViewAutoresizingFlexibleHeig ht|UIViewAutoresizingFlexibleWidth];
// set the background color of the view to black
myView.backgroundColor = [UIColor whiteColor];
// create a frame for the button to go in
CGRect frame = CGRectMake(30, 100, 260, 80);
// create a button
UIButton *snap_picture_button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// set the frame of the button
snap_picture_button.frame = frame;
// create an image for the button
UIImage *snap_picture = [UIImage imageWithContentsOfFile:@"snap_photo.jpg"];
// set the image for the button
[snap_picture_button setBackgroundImage:snap_picture forState:UIControlStateNormal];
// enable the button
snap_picture_button.userInteractionEnabled = YES;
// add the button to the view
[snap_picture_button addTarget:myView
action:@selector(snapPhoto
forControlEvents:UIControlEventTouchUpInside];

// add the button to the view
[myView addSubview:snap_picture_button];

// add myView to the viewController
self.view = myView;
[myView release];
}
ddavtian is offline   Reply With Quote
 

» Advertisements
» Online Users: 590
19 members and 571 guests
Briger, chaseacton, ckgni, crimsoncat, Dani77, diyora, Domele, Gambit, ilmman, nakr, pavanindira, PetarPM, PhillipJames, savvycom, smartbot, spiderguy84, StormFactory, suresk, tonylinux
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,779
Threads: 89,203
Posts: 380,598
Top Poster: BrianSlick (7,129)
Welcome to our newest member, savvycom
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:25 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.