ios - Create a Button with Background Color for Normal/Pressed and Active State -


I'm new to iOS development and want to create a button which will change the background color depending on the following state

<00>
  • Pressed - # 00aa6e
  • Active - # 009762
  • Can I use it without using any image? I have 8 types of buttons in my application and this will increase the size of the asset to use so many pictures.

      - (zero) viewDidoadload {[Super Viewedload]; UIColor * color1 = (UIColor *) UIColorFromRGB (0xFF00FF) ... // Set ur background color here [Set buttonBackground image: [Color with self image: color1] forState: UIControlStateNormal]; [Button setbackground image: [State for self image color: color 2] State: UIControlStateHighlighted]; [Button setbackground display: [self image special color: color 3] forstate: uiControlState selected]; [Button addTarget: auto-action: control event for selector (BTN selected): UIControlEventTouchUpInside]; } + (UIImage *) imageWithColor: (UIColor *) color {CGRect rect = CGRectMake (0.0f, 0.0f, 1.0f, 1.0f); UIGraphicsBeginImageContext (rect.size); CGContextRef Reference = UIGraphicsGetCurrentContext (); CGContextSetFillColorWithColor (Reference, [Color CGColor]); CGContextFillRect (reference, rect); UIImage * image = UIGraphicsGetImageFromCurrentImageContext (); UIGraphicsEndImageContext (); Return image; } - (IBAction) BTN selected: (ID) sender {[selected from sender set: yes]; }  

    setBackgroundImage ur background image will change according to the size of ur button, and please change the size of images for button


    Comments

    Popular posts from this blog

    Member with no value in F# -

    java - Joda Time Interval Not returning what I expect -

    c# - Showing a SelectedItem's Property -