如何在iOS中重复UITextView的背景图像?

时间:2012-11-06 04:21:43

标签: ios xcode

我正在研究一个项目,因为我遇到了问题,当我滚动UITextView时,我为UITextView提供了背景图像,图像重复不固定,所以请告诉任何想法为UITextView修复UIImage。

enter image description here 问候, Raja.I

4 个答案:

答案 0 :(得分:2)

试试这个

textView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed: @"Image.png"]];

答案 1 :(得分:0)

    Use following instance method of UIImage

    - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets

它将返回您不会重复的已调整大小的图像。适用于iOS 5.0及更高版本。您可以从文档中获得更多相关帮助(http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImage_Class/Reference/Reference.html)

答案 2 :(得分:0)

最简单的方法。
将textView背景颜色设置为清除,并在UITextView之前将背景图像作为子视图添加UIImageView。

答案 3 :(得分:0)

请参阅此链接repeat image

UIImage* mars = [UIImage imageNamed:@"Mars.png"];
UIImage* marsTiled = [mars resizableImageWithCapInsets:UIEdgeInsetsZero];
UIImageView* iv = [[UIImageView alloc] initWithFrame:
                   CGRectMake(20,5,mars.size.width,mars.size.height*4)];
//image width is equal to text field width

iv.image = marsTiled;
[self.window.rootViewController.view addSubview:iv];