0

有没有办法访问预设的 UIColor 纹理,然后将它们设置为背景?有点像这样:

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

在此先感谢,德克兰

4

2 回答 2

0

您可以使用以下方法创建 UIImage 类别:

+ (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;
}
于 2013-11-08T11:37:29.103 回答
0

只需将backgroundColor视图的设置为您需要的纹理颜色。

outletWallpaper.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];

此外,您可以UIColour使用[UIColour -colorWithPatternImage:]API 加载自己的图像并将它们用作:

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

outletWallpaper.backgroundColor = colourPattern;
于 2013-11-08T16:28:44.793 回答