2009-04-17 3 views

답변

71

배경 이미지가 포함되어 있고 형제가 UITextView 인 경우 인터페이스 작성기에서 텍스트보기를 이미지보기와 겹치도록 이동하거나 프로그래밍 방식으로 동일한 부모보기에 추가 할 수 있습니다. 또한 텍스트보기가 불투명도가 아닌이 아니고 불투명도 배경이으로 지정되어 있는지 확인해야합니다. @oxigen에서 대답 # 9을하려고 할 때

+10

배경 이미지에 "아래쪽 테두리"가있는 경우 oxigen의 방법에서 내 대답은 내 대답은 텍스트를 입력 할 때 텍스트보기와 함께 스크롤하는 것을 볼 수 있습니다. – bpapa

+0

+1 멋진 트릭.+1은 @bpapa에 동의합니다. –

+2

UIImageView에 형제를 얼마나 정확히 추가합니까? – jacobronniegeorge

1

확실하지,하지만 당신은 배경 이미지가있는 UIImageView에 의해 처리된다고 가정하면, 다음을 시도 할 수 있습니다 :

[myTextView addSubview : myImageView]

UITextView의 알파/불투명 속성 값을 변경해야 할 수도 있습니다.

종류 감사합니다.

45
UITextView *textView = [[UITextView alloc]initWithFrame: window.frame]; 
textView.text = @"text\n text\n text"; 
UIImageView *imgView = [[UIImageView alloc]initWithFrame: textView.frame]; 
imgView.image = [UIImage imageNamed: @"myImage.jpg"]; 
[textView addSubview: imgView]; 
[textView sendSubviewToBack: imgView]; 
[window addSubview: textView]; 
+7

이 답변에 설명 된 방법으로 "백그라운드 이미지"가 사용자 유형별로 내용과 함께 스크롤되기 때문에 duncanwilcox의 대답이 바람직하다고 생각합니다. – bpapa

+1

할당 된 개체를 해제해야합니다. 이후 : [textView addSubview : imgView]; 추가 : [imgView release]; 끝에 추가 : [textView release]; – ma11hew28

+0

더 나은 이미지 품질을 원하면 이미지 크기를 조정하십시오! – Mateus

11

그냥 하나의 설명은,이 선 것을 발견 :

UIImageView *imgView = [[UIImageView alloc]initWithFrame: textView.frame]; 

textView.frame를 기준으로합니다.

UIImageView *imgView = [[UIImageView alloc]initWithFrame:textView.bounds]; 
+0

또는 적은 타이핑으로 :'(...) initWithFrame : textView.bounds' –

41

@durai : 그래서 xy 값은 당신이 당신이 뭔가를 원하는 뜻을 완전히 겹쳐하려는 경우 0,0 일 필요 귀하의 이미지는 흰색 배경이 나타납니다 후 높이 제한이 있습니다 아래로 스크롤 한 후 빈 배경이 나타나면 동일한 이미지를 반복 할 수 있습니다.

이 도움이 될 수 있습니다 타일 배경에 대한

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

upvoting - 왜 누군가가 이것을 downvote 모르겠; 그것은 멋진 솔루션입니다. – TomSwift

+0

이것은 하나입니다! –

+0

이 답변과 @duncanwilcox의 답변은 모두 좋습니다. 배경을 스크롤할지 여부에 따라 다릅니다. – memmons

2

은 내가 배경 이미지를 설정하는 방법을 하나의 간단한 방법을 발견

UIImage *patternImage = [UIImage imageNamed:@"image.png"]; 
UIColor* color = [UIColor colorWithPatternImage:patternImage]; 
textView.backgroundColor = color; 
1
UITextView *textView=[[UITextView alloc]initWithFrame: CGRectMake(20, 20, 40, 40)]; 
textView.text = @"this is a test \n this is test \n this is a test"; 
UIImageView *img = [[UIImageView alloc]initWithFrame: textView.frame]; 
img.image = [UIImage imageNamed: @"image.png"]; 
[self.view addSubview:textView]; 
[self.view insertSubview:img belowSubview:textView]; 
6

이 솔루션을 좋아한다.

시간 파일

@interface FNTextView : UITextView 

@end 

m 파일

... 
- (void)drawRect:(CGRect)rect 
{ 
    [self.bgImage drawInRect:rect]; 

    [super drawRect:rect]; 
} 

- (void)initHandler 
{ 
    self.bgImage = [[UIImage imageNamed:@"textview_bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(4, 4, 4, 4)]; 
} 
... 
1

@dulcanwilcox의 답변 @oxigen 모두 일을하지만, 가산 이미지 경우, 배경 이미지의 크기를 재조정 할 수 있도록하는 것입니다 어떤 종류의 국경을 보여주기 위해 사용되고 있습니다.

UITextView *textView = [[UITextView alloc]initWithFrame: window.frame]; 
textView.text = @"Some text..."; 

UIImageView *imgView = [[UIImageView alloc]initWithFrame: textView.frame]; 
imgView.image = [[UIImage imageNamed: @"image"] resizableImageWithCapInsets:UIEdgeInsetsMake(8, 8, 8, 8)]; 

[textView addSubview:imgView]; 
[textView sendSubviewToBack:imgView]; 

[window addSubview:textView]; 

resizableImageWithCapInsets:(UIEdgeInsets)capInsets에 대한 설명서를 확인하십시오.

5
[txtView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"image.png"]]];