문제

배경 이미지를 어떻게 설정하나요? UITextView?

도움이 되었습니까?

해결책

당신은 가질 수 있습니다 UIImageView 배경 이미지와 UITextView 형제 자매로서 인터페이스 빌더에서 텍스트보기를 이동하여 이미지보기를 겹치거나 (프로그래밍 방식으로 수행 할 경우 동일한 상위보기에 둘 다 추가). 또한 텍스트보기가 아닌지 확인해야합니다. 불투명체 그리고 그것을 줘 0% 불투명어 배경.

다른 팁

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];

@Durai : 이미지의 높이 제한이있는 후에는 흰색 배경이 표시되면 빈 배경이 표시되면 아래로 스크롤 한 후 동일한 이미지를 반복 할 수 있습니다.

도움이 될 수 있습니다.

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

답변 #9를 시도 할 때 한 가지 설명 만 @oxigen, 나는이 줄을 발견했다 :

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

Is relative to the textView.frame. 그래서 당신의 x 그리고 y 완전히 겹치려면 값이 0,0이어야합니다.

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

배경 이미지를 설정하는 방법 중 하나를 찾았습니다.

H 파일

@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)];
}
...
[txtView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"image.png"]]];

타일 ​​배경의 경우 이 솔루션이 마음에 듭니다.

UIImage *patternImage = [UIImage imageNamed:@"image.png"];
UIColor* color = [UIColor colorWithPatternImage:patternImage];
textView.backgroundColor = color;

확실하지 않지만 배경 이미지가 uiimageview에 의해 처리된다고 가정 할 때 다음을 시도 할 수 있습니다.

MyTextView AddSubview : MyImageView];

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

친절한 안부.

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];

@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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top