如何在文本區域放置模板的背景圖像?如何在文本區域放置背景圖像(在IPAD中)
回答
不知道你的意思「template'd」什麼......但....
在Interface Builder中,添加ImageView的TextView的背後,取消選中「不透明」框TextView的。
如果您要添加的圖像programmaticaly我設法做這種方式:
首先在我textviewViewController.h我增加了一個出口的UITextView的。
#import <UIKit/UIKit.h>
@interface textviewViewController : UIViewController {
UITextView *textView;
}
@property (nonatomic, retain) IBOutlet UITextView *textView;
@end
接下來,在我的.xib中,我添加了我的UITextView並連接了我的插座。
最後在textviewViewController.m的viewDidLoad中,我將該圖像作爲子視圖添加到我的textview中。
- (void)viewDidLoad {
[super viewDidLoad];
// Change the pathForResource to reflect the name and type of your image file
NSString *path = [[NSBundle mainBundle] pathForResource:@"d" ofType:@"jpg"];
UIImage *img = [UIImage imageWithContentsOfFile:path];
UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
[self.textView insertSubview:imgView atIndex:0];
[imgView release];
}
我試過insertSubview:atIndex:既0和1具有相同的結果,但我會用0 idicating它的TextView的背後貼。
'[self.textView insertSubview:imgView atIndex:0];'將圖像插入到textView中,而不是在後面。使用'[[self.textView superview] insertSubview:imgViewSubview:self.textView];'把它放在textView後面,假設superview不是零。後者不會隨文本一起滾動。插入後不要忘記釋放imgView。 – drawnonward 2010-05-28 03:36:59
感謝drawnonward,你是對的我忘了發佈我的imgView。由於這是在我的視圖控制器中,imageView可以通過[self.view insertSubview:]插入到主視圖中,但是我得到了imageView被視爲textview一部分的印象。 – thelaws 2010-06-02 02:03:03
您可以設置文本視圖圖層的內容屬性。
#import <QuartzCore/QuartzCore.h>
...
- (void) viewDidLoad {
[super viewDidLoad];
textView.layer.contents = (id)[UIImage imageNamed:@"myImage.png"].CGImage
}
應該工作
- 1. 文本區域的背景圖像
- 2. 將背景圖像放在文本上?
- 3. 如何更改文本區域的背景圖像
- 4. 如何在背景圖像上放置圖像
- 5. 如何使用CSS放置背景圖像高於文本?
- 6. 如何在使用SCILAB的圖形中放置背景圖像?
- 7. CSS背景圖像放置在:懸停
- 8. 如何將背景圖像放置在android的文本視圖的左上角?
- 9. 將圖像置於身體後放入文本(背景圖像)
- 10. 在背景圖像上設置可點擊區域
- 11. 動作腳本3:如何設置圖表區域背景?
- 12. 如何在窗口的背景中放置圖像
- 13. 如何在容器中間放置背景圖像?
- 14. 如何在div中放置(背景)圖像?
- 15. 如何在水晶中放置背景圖像Report Report
- 16. 如何在另一個背景圖像背後設置背景?
- 17. 如何使用Canvas或jQuery將圖像和文本放在背景圖像上?
- 18. PHP:如何使圖像中的綠色區域(背景)透明?
- 19. 在LinearLayout中縮放背景圖像
- 20. 如何在背景鏈接圖像上放置ul元素?
- 21. Gnuplot繪圖區域背景
- 22. c3圖表背景區域
- 23. CSS背景圖像。在文字位置
- 24. 在背景圖像背景圖像
- 25. 如何在背景div baloon圖像中居中文本?
- 26. 移動Safari文本區域背景
- 27. 如何在文本輸入中添加放置區域?
- 28. 在圖像上放置一個背景圖像
- 29. 在圖像背景上放置圖像按鈕
- 30. 我可以在圖表的背景中放置圖像嗎?
嘗試這個現在WKW!如果它有效,你的答案就會贏! – 2010-05-25 20:06:49
你如何把textview放在textview後面? – 2010-05-26 06:24:19
您只需放入圖像視圖,您可能必須更改textview的z順序,使其位於圖像視圖之上。 – Ukko 2010-05-27 18:33:16