如何像Notes App一样设置UITextView的内容插图 [英] How to set UITextView's content inset like Notes App

查看:64
本文介绍了如何像Notes App一样设置UITextView的内容插图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个应用程序中工作,需要在iphone中提供类似Notes App的功能.如第一个屏幕截图所示,最初,笔记在内容开始之前留有一个标签,我也想这样做,为此,当我将UITextView的 Left Content inset 设置为25时,它显示就像截图2一样,在这里您可能会看到图像也偏移了.我已将图像设置为背景.我不知道如何解决这个问题.

I am working in an app in which I need to give feature like Notes App in iphone. as shown in first screen shot , initially , notes leaves a tab before the content starts, I also wanted to do the same and for that when I set Left Content inset (of UITextView) by 25 , it shows like in screenshot 2, here you may see the image also gets shifted. I have set image as background. I don't know how to solve this problem.

我还尝试过将图像添加为UITextview的子视图,但是在滚动(行的图像)(如注释应用程序)时,它不会重复行.

I also tried by adding image as subview of UITextview but it won't repeat the lines, while scrolling (image of lines) like notes app.

我通过以下代码设置Textview的背景.

I'm setting the background of Textview by following code.

[textView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"line_image.png"]]];

请告诉我是否要出错或需要任何额外的努力才能获得所需的输出.

Please tell me if I am going wrong or any extra effort needed to get desired output.

谢谢

推荐答案

@Dinesh提供了很好的解决方案,但是听起来不太通用,因为我想使用线条图像而不是绘制线条.图像具有一些无法通过绘图获得的特殊效果.因此,为了解决该问题,我在textview下方创建了一个表格视图,以保持textview的背景透明.现在只需将line的图像添加到我的tableview的自定义单元格中,并将UItableview的内容偏移设置为与scrollview(文本视图的子视图,请参阅@Vladimir的答案)相同.

@Dinesh gave nice solution but it doesn't sound to be generic as I want to use image of lines instead of drawing them. Image has some special effects that can not be achieved by drawing. So to solve it I created a table view below the textview keeping textview's background transparent. Now just added the image of line to my tableview's custom cell and set content offset of UItableview same as of the scrollview (subview of text view ,refering to the answer of @Vladimir ) .

并使用以下代码来滚动表格视图和滚动文本视图,并获得所需的输出.

And used the following code to scroll my tableview with scrolling the textview and got the desired output.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{           
    tableView.contentOffset =scrollView.contentOffset; 
}

保持我的tableview的行数非常大.

Keeping my tableview's number of rows at a very large number.

PS:我没有设置textview的内容插图,而是设置了其框架的 X位置,并相对减小了宽度.

PS: instead of setting the content inset of textview, i set its frame's X position and decreased the width relaively.

这篇关于如何像Notes App一样设置UITextView的内容插图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆