UITextView background image

后端 未结 10 2032
说谎
说谎 2020-12-02 08:44

How can I set up a background image to UITextView?

10条回答
  •  悲&欢浪女
    2020-12-02 09:37

    The answers of @dulcanwilcox and @oxigen both work, but, an addition would be to make the background image resizable, in case the image is being used to show some kind of border.

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

    Check out the documentation for resizableImageWithCapInsets:(UIEdgeInsets)capInsets.

提交回复
热议问题