有没有办法访问预设的 UIColor 纹理,然后将它们设置为背景?有点像这样:
UIColor *mytexture = [UIColor scrollViewTexturedBackgroundColor];
UIImage *myimage = [UIImage imageWithData:mytexture];
[outletWallpaper setImage:myimage];
在此先感谢,德克兰
有没有办法访问预设的 UIColor 纹理,然后将它们设置为背景?有点像这样:
UIColor *mytexture = [UIColor scrollViewTexturedBackgroundColor];
UIImage *myimage = [UIImage imageWithData:mytexture];
[outletWallpaper setImage:myimage];
在此先感谢,德克兰
您可以使用以下方法创建 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;
}
只需将backgroundColor
视图的设置为您需要的纹理颜色。
outletWallpaper.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
此外,您可以UIColour
使用[UIColour -colorWithPatternImage:]
API 加载自己的图像并将它们用作:
UIImage *myImage = [UIImage imageNamed:@"anImageFile"];
UIColour colourPattern = [UIColor colorWithPatternImage: myImage];
outletWallpaper.backgroundColor = colourPattern;