Question

Is there any way of accessing the preset UIColor Textures, then setting them as a background? Sort of like this:

UIColor *mytexture = [UIColor scrollViewTexturedBackgroundColor];
UIImage *myimage = [UIImage imageWithData:mytexture];
[outletWallpaper setImage:myimage];

Thanks in advance, Declan

Was it helpful?

Solution

Just set the backgroundColor of the view to the texture colour you require.

outletWallpaper.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];

In addition you can load your own images and use them as a UIColour by using the [UIColour -colorWithPatternImage:] API:

UIImage *myImage = [UIImage imageNamed:@"anImageFile"];
UIColour colourPattern = [UIColor colorWithPatternImage: myImage];

outletWallpaper.backgroundColor = colourPattern;

OTHER TIPS

You can create category of UIImage with method like this:

+ (UIImage *)imageWithColor:(UIColor *)color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return image;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top