Results 1 to 1 of 1

How To a Make UIButton with Background Image Programmatically

This is a discussion on How To a Make UIButton with Background Image Programmatically within the iPhone/iPad Programming Tutorials forums, part of the Programming Section category; Hello, Here is how to code a UIButton with a Background image. In you ViewController.m file: Code: UIButton *roundedButtonType = ...

          
   
  1. #1
    The Man Behind It All Fahad's Avatar
    Join Date
    Jun 2009
    Posts
    813

    Default How To a Make UIButton with Background Image Programmatically

    Hello,

    Here is how to code a UIButton with a Background image.


    In you ViewController.m file:

    Code:
    
    	UIButton *roundedButtonType = [[UIButton buttonWithType:UIButtonTypeCustom] retain]; //Creates a UIButton
    
    	roundedButtonType.frame = CGRectMake(200, 368, 95, 37); //sets the coordinates and dimensions of UIButton
    
    	roundedButtonType.backgroundColor = [UIColor clearColor]; //sets the background color
    
    	[roundedButtonType addTarget:self action:@selector(returnmainview:) forControlEvents:UIControlEventTouchUpInside]; //sets the Background image 
    
    	[roundedButtonType setTitle:@"title" forState:UIControlStateNormal]; //set the title
    
    	[roundedButtonType setBackgroundImage:[UIImage imageNamed:@"chrome.png"] forState:UIControlStateNormal]; //sets the background Image
    
    	[roundedButtonType setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    IF YOU NEED ANY HELP PLEASE DON'T HESITATE TO ASK BY LEAVING A REPLAY BELOW
    Last edited by Fahad; 01-10-2011 at 06:08 AM.



    MozyMac Founder,Chairman and CEO

    MacBook Pro Unibody late 2008 2.4Ghz 4GB ram 250GB HD

    MozyMac Youtube Channel

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •