我有以下代码:

UIImageView *imgView = [[UIImageView alloc]initWithFrame: description.frame];
imgView.image = [UIImage imageNamed: @"textview.png"];
[description addSubview: imgView];
[description sendSubviewToBack: imgView];
[imgView release];


这里的描述是一个UITextView。我有一张要设置为背景的图像。但是,结果界面如下所示:



图像的大小与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];


图像未放置在正确的位置,因为您的description.frame.origin.x!= 0,由于这个原因,您遇到了错误。

关于iphone - UIImageView作为UITextView的背景,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6182921/

10-13 04:02