我是Obj-C/Cocoa Touch/iPhone OS的初学者.
我想在每次调用视图时为我的应用程序提供不同图像的背景.
说我有10张图片.我这样用它:
//random image generation
NSString* imageName;
int aRandomNumber = arc4random() % 10;
imageName =[NSString stringWithFormat:@"g%d.jpg",aRandomNumber];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:imageName]]];
NSLog(@"aRandomNumber is %d", aRandomNumber);
//random image is generated
Run Code Online (Sandbox Code Playgroud)
它的工作正常
我怎么能用UIView/UIImageView做到这一点?
我initWithHue:saturation:brightness:alpha:
在文档中找到但它不起作用:
self.view.backgroundColor = [[UIColor alloc] initWithHue:0.0 saturation:1.0 brightness:1.0 alpha:1.0];
Run Code Online (Sandbox Code Playgroud)
请帮忙!
朋友建议........
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:imageName]]];
Run Code Online (Sandbox Code Playgroud)
..........他告诉它更高效,因为它不会将图像保存在缓存中.
我只是Objective-C的初学者,它的语法只是让我失去理智.
我正在'尝试'在iphone 3.0上工作.
直到知道我已经了解到:
那么我们如何调用我们选择的函数/方法呢?
在C,C++,JAVA,C#的旧语言格式中,我们有一个main()函数来完成我们的控制工作,但它在Obj-c中的main()是什么?
我知道有一个main()函数,但我几乎不知道它是如何工作的.