我是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
它的做工精細現在
- ,說我有我的看法文本標籤和文字不會因圖像顏色正確顯示。 如何讓它變得透明一點? (我想在Interface Builder中稱其爲alpha。)
- 說我的圖像不是320x480。我如何設置它以填充整個視圖?
我該怎麼做UIView/UIImageView?
我發現文檔中initWithHue:saturation:brightness:alpha:
,但它不工作:
self.view.backgroundColor = [[UIColor alloc] initWithHue:0.0 saturation:1.0 brightness:1.0 alpha:1.0];
請幫助!
一個朋友建議........
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:imageName]]];
..........他告訴它的效率更高,因爲它不保存在圖像緩存。
一個朋友建議使用此..... ... self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:[[[NSBundle main Bundle] resourcePath] stringByAppendingPathComponent:imageName]]]; ..........他告訴它更高效率,它不會將圖像保存在緩存中。 – Daniel 2010-01-30 11:02:33