在TextView后面添加背景图片

发布于 2024-10-18 21:00:49 字数 43 浏览 0 评论 0原文

嘿伙计们, 有谁知道如何使文本视图透明并在文本视图后面添加背景图像?谢谢

Hey guys,
Does anyone know how to make the Text View transparent and add a Background Image behind the Text View? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

西瑶 2024-10-25 21:00:49

在 viewDidLoad 中

textView.backgroundColor = [UIColor clearColor];
UIImageView *imageView = [[[UIImageView alloc] initWithFrame:textView.frame] autorelease];
imageView.image = [UIImage imageNamed:@"myBackgroundImage.png"];
[self.view addSubview:imageView];
[self.view bringSubviewToFront:textView];

In viewDidLoad

textView.backgroundColor = [UIColor clearColor];
UIImageView *imageView = [[[UIImageView alloc] initWithFrame:textView.frame] autorelease];
imageView.image = [UIImage imageNamed:@"myBackgroundImage.png"];
[self.view addSubview:imageView];
[self.view bringSubviewToFront:textView];
メ斷腸人バ 2024-10-25 21:00:49

尝试创建一个新类。 (没有测试代码,只是在论坛上输入的,尝试使用代码否则:使用概念)

@interface TextViewWithImage : UIView {
   UITextView *textView;
   UIImageView *imageView;
}

@property (retain, readonly) UITextView *textView;
@property (retain, readonly) UIImageView *imageView;

@implementation TextViewWithImage

- (id) init {
   if (self = [super init]) {
      [self setupContentViews];
   }
   return self;
}

- (id) initWithFrame:(CGRect)frame {
   if (self = [super initWithFrame:frame]) {
      [self setupContentViews];
   }
   return self;
}

- (void) setupContentViews {
   textView = [[UITextView alloc] init];
   imageView = [[UIImageView alloc] init];

   textView.frame = self.frame;
   imageView.frame = self.frame;

   textView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
   imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}

- (void) dealloc {
   [textView release];
   [imageView release];
   [super dealloc];
}
@end

Try to make a new class. (Did not test the code, just typed it on the forum, try to use the code otherwise: use the concept)

@interface TextViewWithImage : UIView {
   UITextView *textView;
   UIImageView *imageView;
}

@property (retain, readonly) UITextView *textView;
@property (retain, readonly) UIImageView *imageView;

@implementation TextViewWithImage

- (id) init {
   if (self = [super init]) {
      [self setupContentViews];
   }
   return self;
}

- (id) initWithFrame:(CGRect)frame {
   if (self = [super initWithFrame:frame]) {
      [self setupContentViews];
   }
   return self;
}

- (void) setupContentViews {
   textView = [[UITextView alloc] init];
   imageView = [[UIImageView alloc] init];

   textView.frame = self.frame;
   imageView.frame = self.frame;

   textView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
   imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}

- (void) dealloc {
   [textView release];
   [imageView release];
   [super dealloc];
}
@end
|煩躁 2024-10-25 21:00:49

UIViews(UITextView 是其子类)有一个名为backgroundColor 的属性。

@property(nonatomic, copy) UIColor *backgroundColor

尝试在 TextView 上调用 [textView setBackgroundColor:[UIColor clearColor]] 并在其后面放置一个图像视图。

UIViews (of which UITextView is a subclass) have a property called backgroundColor.

@property(nonatomic, copy) UIColor *backgroundColor

Try calling [textView setBackgroundColor:[UIColor clearColor]] on the TextView and putting an image view behind it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文