Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Change UIIMage background color in iOS

    • 0
    • 0
    • 0
    • 0
    • 2
    • 0
    • 0
    • 0
    • 2.84k
    Comment on it

    Here is a function which returns an image with different background of you choice.

    - (UIImage* )setBackgroundImageByColor:(UIColor *)backgroundColor withFrame:(CGRect )rect{
    // tcv - temporary colored view
    UIView *tcv = [[UIView alloc] initWithFrame:rect];
    [tcv setBackgroundColor:backgroundColor];
    // set up a graphics context of button's size
    CGSize gcSize = tcv.frame.size;
    // add tcv's layer to context
    [tcv.layer renderInContext:UIGraphicsGetCurrentContext()];
    // create background image now
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    return image;
    //    [tcv release];

    It will return you an image with blue background color. Happy Coding!!!

 2 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: