배경 이미지를 UITextView
으로 설정하려면 어떻게해야합니까?UITextView 배경 이미지
답변
배경 이미지가 포함되어 있고 형제가 UITextView
인 경우 인터페이스 작성기에서 텍스트보기를 이미지보기와 겹치도록 이동하거나 프로그래밍 방식으로 동일한 부모보기에 추가 할 수 있습니다. 또한 텍스트보기가 불투명도가 아닌이 아니고 불투명도 배경이으로 지정되어 있는지 확인해야합니다. @oxigen에서 대답 # 9을하려고 할 때
확실하지,하지만 당신은 배경 이미지가있는 UIImageView에 의해 처리된다고 가정하면, 다음을 시도 할 수 있습니다 :
[myTextView addSubview : myImageView]
UITextView의 알파/불투명 속성 값을 변경해야 할 수도 있습니다.
종류 감사합니다.
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];
그냥 하나의 설명은,이 선 것을 발견 :
UIImageView *imgView = [[UIImageView alloc]initWithFrame: textView.frame];
가 textView.frame
를 기준으로합니다.
UIImageView *imgView = [[UIImageView alloc]initWithFrame:textView.bounds];
또는 적은 타이핑으로 :'(...) initWithFrame : textView.bounds' –
@durai : 그래서 x
및 y
값은 당신이 당신이 뭔가를 원하는 뜻을 완전히 겹쳐하려는 경우 0,0 일 필요 귀하의 이미지는 흰색 배경이 나타납니다 후 높이 제한이 있습니다 아래로 스크롤 한 후 빈 배경이 나타나면 동일한 이미지를 반복 할 수 있습니다.
이 도움이 될 수 있습니다 타일 배경에 대한
textView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed: @"Image.png"]];
은 내가 배경 이미지를 설정하는 방법을 하나의 간단한 방법을 발견
UIImage *patternImage = [UIImage imageNamed:@"image.png"];
UIColor* color = [UIColor colorWithPatternImage:patternImage];
textView.backgroundColor = color;
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];
이 솔루션을 좋아한다.
시간 파일
@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)];
}
...
@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에 대한 설명서를 확인하십시오.
[txtView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"image.png"]]];
배경 이미지에 "아래쪽 테두리"가있는 경우 oxigen의 방법에서 내 대답은 내 대답은 텍스트를 입력 할 때 텍스트보기와 함께 스크롤하는 것을 볼 수 있습니다. – bpapa
+1 멋진 트릭.+1은 @bpapa에 동의합니다. –
UIImageView에 형제를 얼마나 정확히 추가합니까? – jacobronniegeorge