Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QButtonElement gradiend background #479

Closed
BossOz opened this issue Apr 21, 2013 · 3 comments
Closed

QButtonElement gradiend background #479

BossOz opened this issue Apr 21, 2013 · 3 comments

Comments

@BossOz
Copy link

BossOz commented Apr 21, 2013

Is possibile to make a QButtonElement with a gradiend background?
The standard on is very "flat" :D

Tnks
Oscar

@BossOz
Copy link
Author

BossOz commented Apr 22, 2013

Schermata 2013-04-22 alle 18 34 11

if ([element isKindOfClass:[QButtonElement class]]){
    cell.textLabel.textColor = [UIColor whiteColor];

    CGFloat colors[8] = { 158.0 / 255, 198.0 / 255, 153.0 / 255, 1,
                          13.0 / 255, 157.0 / 255, 35.0 / 255, 1 };
    CGFloat locations[2] = { 0.0, 1.0 };

    CGColorSpaceRef baseSpace = CGColorSpaceCreateDeviceRGB();
    CGGradientRef myGradient = CGGradientCreateWithColorComponents(baseSpace, colors, locations, 2);
    // Allocate color space
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    // Allocate bitmap context
    CGContextRef bitmapContext = CGBitmapContextCreate(NULL, cell.frame.size.width, cell.frame.size.height, 8, 4 * 320, colorSpace, kCGImageAlphaNoneSkipFirst);
    // Draw Gradient Here
    CGContextDrawLinearGradient(bitmapContext, myGradient, CGPointMake(0, cell.frame.size.height), CGPointMake(0.0f, 0.0f), 0);
    // Create a CGImage from context
    CGImageRef cgImage = CGBitmapContextCreateImage(bitmapContext);
    // Create a UIImage from CGImage
    UIImage *uiImage = [UIImage imageWithCGImage:cgImage];
    // Release the CGImage
    CGImageRelease(cgImage);
    // Release the bitmap context
    CGContextRelease(bitmapContext);
    // Release the color space
    CGColorSpaceRelease(colorSpace);
    // Create the patterned UIColor and set as background color
    //[cell setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"backGreenButton.png"]]];
    [cell setBackgroundColor:[UIColor colorWithPatternImage:uiImage]];
}

used in
(void)cell:(UITableViewCell *)cell willAppearForElement:(QElement *)element atIndexPath:(NSIndexPath *)indexPath

@fechu
Copy link

fechu commented Sep 11, 2013

I think it would be worth it to implement this as a new property and perhaps define some default color schemes like success, warning and error. What do you think?

@escoz
Copy link
Owner

escoz commented Sep 11, 2013

Making this a property in the element is not the solution, I would say. It'll be a big problem once you move to iOS7. The property is already available in the QAppearance class, simply create new appearance object for the button and set the image background or background color there. The sample app does that: LoginController.m, line 40.

@escoz escoz closed this as completed Sep 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants