ios uiview uiimageview uitextview
我有一个主 UIView,上面有一个 UIImageView,并且 UIView 添加了一个 UITextView 作为子视图。 UITextView的框架比UIView小。 UIImageView 实际上是一个框架,图像的其余部分是透明的并且适合 UIView 的完整大小,但 UITextView 始终位于 UIView 之上。我想要实现的是 UITextView 在前台显示 UIView,同时可以在 UITextView 上上下滚动。
使其成为可能的正确方法是什么?
我当前的代码不起作用:
in loadView
:
self.contentview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
self.contentview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ChristmasFrame.png"]];
self.contentview.opaque = NO;
self.contentview.userInteractionEnabled = YES;
[self setView:self.contentview];
in viewDidLoad
:
[self.contentview addSubview:self.textview];
[self.contentview sendSubviewToBack: self.textview];
我希望 UITextView 位于 self.contentview 后面,这样它就可以在 UITextView 上显示其背景图像。
I have a main UIView that has an UIImageView on it, and the UIView adds an UITextView as a subview. UITextView's frame is smaller than UIView. UIImageView is actually a frame and the rest of the image is transparent and fits the full size of the UIView, but the UITextView is always upon UIView. What I want to achieve is UITextView shows UIView in foreground, while it is possible to scroll up and down on UITextView.
What is the proper way to make it possible?
My current code that does not work:
in loadView
:
self.contentview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
self.contentview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ChristmasFrame.png"]];
self.contentview.opaque = NO;
self.contentview.userInteractionEnabled = YES;
[self setView:self.contentview];
in viewDidLoad
:
[self.contentview addSubview:self.textview];
[self.contentview sendSubviewToBack: self.textview];
I want UITextView to be behind self.contentview, so it could show its background image upon the UITextView.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在
UITextView
之上的UIView
上将setUserInteractionEnabled:
设置为NO
如果这不起作用,您可以尝试覆盖
hitTest:withEvent:
try setting
setUserInteractionEnabled:
toNO
onUIView
what is on top ofUITextView
if that not working you could try to override
hitTest:withEvent:
将清晰的颜色设置为textview的背景色。
并在 UIView 上方添加文本视图
make clear color as textview's background color.
and add text view above UIView