UITextView背景画像
-
09-09-2019 - |
質問
設定はどのように行うのですか、背景画像を 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: イメージは高さ制限なし、その後は白背景をされていない場合に表示されま空を背景と表示されますので巻downしたときに繰り返し同じイメージです。
このヒントとなるような:
textView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed: @"Image.png"]];
ちょうど1明確化、
UIImageView *imgView = [[UIImageView alloc]initWithFrame: textView.frame];
textView.frame
に相対的です。あなたはそれがあなたのような何かをしたい意味し、完全に重なるようにしたいのであれば、あなたのx
とy
値は0,0である必要があります:
UIImageView *imgView = [[UIImageView alloc]initWithFrame:textView.bounds];
私はどのように背景画像を設定する1つの簡単な方法を見つけます。
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するます。