This is a discussion on How To a Make UIButton with Image Programmatically (by coding) within the iPhone/iPad Programming Tutorials forums, part of the Programming Section category; Hello, Here is how to code a UIButton with an image inside it. 1) Open your Viewcontroller.h file and the ...
Hello,
Here is how to code a UIButton with an image inside it.
1) Open your Viewcontroller.h file and the following:
In your ViewController.m file add the following:Code:@interface ButtonsViewController : UIViewController { UIButton *imageButton; } @property (nonatomic, retain) UIButton *imageButton; @end
IF YOU NEED ANY HELP PLEASE DON'T HESITATE TO ASK BY LEAVING A REPLAY BELOWCode:- (void)viewDidLoad { imageButton = [UIButton buttonWithType:UIButtonTypeCustom]; //sets the type of UIButton imageButton.frame = CGRectMake(150, 119, 71, 31); //sets the coordinates and dimensions of UIButton imageButton.backgroundColor = [UIColor clearColor]; //sets the background color [imageButton setBackgroundImage:[UIImage imageNamed:@"chrome.png"] forState:UIControlStateNormal]; //sets the Background image [imageButton setImage:[UIImage imageNamed:@"UIButton_custom.png"] forState:UIControlStateNormal]; //sets the image [super viewDidLoad]; [self.view addSubview:imageButton]; }![]()
here is a screenshot of the result:
![]()
MozyMac Founder,Chairman and CEO
MacBook Pro Unibody late 2008 2.4Ghz 4GB ram 250GB HD
MozyMac Youtube Channel