如何在文本区域上放置背景图像(在IPAD中)

时间:2010-04-20 20:16:17

标签: xcode ios-simulator ipad

如何在文本区域放置模板背景图片?

3 个答案:

答案 0 :(得分:9)

不确定你对“模板”的意思......但...... ....

在界面构建器中,在textview后面添加imageview,取消选中textview的“opaque”框。

答案 1 :(得分:7)

您可以设置文本视图图层的contents属性。

#import <QuartzCore/QuartzCore.h>

...

- (void) viewDidLoad {
    [super viewDidLoad];
    textView.layer.contents = (id)[UIImage imageNamed:@"myImage.png"].CGImage
}

应该有效

答案 2 :(得分:-2)

如果你想以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都有相同的结果,但我会坚持认为它是在textview后面的。