开发者

UIImageView as background of UITextView

I have the following code:

UIImageView *imgView = [[UIImageView 开发者_JS百科alloc]initWithFrame: description.frame];
imgView.image = [UIImage imageNamed: @"textview.png"];
[description addSubview: imgView];
[description sendSubviewToBack: imgView];
[imgView release];

where description here is a UITextView. I have an image that I would like to set as the background of this. However the resulting interface looks like this:

UIImageView as background of UITextView

The size of the image is exactly the same as the size of the UITextView


UIImageView *imgView = [[UIImageView alloc]initWithFrame: CGRectMake(0,0,description.frame.size.width,description.frame.size.height)];
imgView.image = [UIImage imageNamed: @"textview.png"];
[description addSubview: imgView];
[description sendSubviewToBack: imgView];
[imgView release];

the image is not placed at right place because your description.frame.origin.x != 0, its due to this reason you are getting bug.


Instead of UITextView you can use the UILabel and set the UILable color to colorless. then you will get the desired output..


You can add imageView(with you image) into your nib file and then place textView upon it.


You can set the image as background as follows:

UITextView *view = [[UITextView alloc] initWithFrame: CGRectMake(x,y,width,height)];
view.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"imagename.png"]];

[self.view addSubView: text];

Hope this helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜