UITextView contentInset 不起作用

use*_*826 4 objective-c uitextview ios ios6 uiedgeinsets

我在 UITextView 中显示文本。我需要对文本应用一些填充。当我使用最高位置的价值时,它就起作用了。如果我将价值用于其他职位,则它不起作用。

 txtt_bgImage     = [UIImage imageNamed:@"txtt_bg_ipad.png"];
                  txtt_bgImageView = [[UIImageView alloc] initWithImage:txtt_bgImage];

          txtt=[[UITextView alloc]initWithFrame:CGRectMake(170, 300, 400, 250)];

          txtt.text=productDescription;



                  [txtt  setFont: [UIFont fontWithName:@"verdana" size:15]];

                  txtt.textColor=[UIColor whiteColor];

                  [txtt setBackgroundColor:[UIColor clearColor]];


                  txtt.contentInset = UIEdgeInsetsMake(15,0,0,0);

                //  [txtt  setTextContainerInset:UIEdgeInsetsMake(7, 7, 0, 0)];

                  txtt_bgImageView.frame=CGRectMake(170, 300, 400, 250);


                  [self.view addSubview:txtt_bgImageView];

                  txtt.editable=NO;

          NSLog(@"text is %@",txtt.text);

                   object.object_screentext = txtt;

          [self.view addSubview:txtt];
Run Code Online (Sandbox Code Playgroud)

Nit*_*hel 5

对于 iOS7 使用 textContainerInset

@property(nonatomic, assign) UIEdgeInsets textContainerInset NS_AVAILABLE_IOS(7_0);
Run Code Online (Sandbox Code Playgroud)

对于 Bellow iOS7 使用contentInset和设置UIEdgeInsetsMake为波纹管语法。

UIKIT_STATIC_INLINE UIEdgeInsets UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right) {
    UIEdgeInsets insets = {top, left, bottom, right};
    return insets;
}
Run Code Online (Sandbox Code Playgroud)

根据您的代码,您仅设置顶部插入但如果您希望设置所有侧面,则必须设置如下内容插入:-

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
       _TxtViewSummary.contentInset = UIEdgeInsetsMake(10, 0, 10, 0);
    } else {
       _TxtViewSummary.textContainerInset = UIEdgeInsetsMake(10, 10, 10, 10);
    }
Run Code Online (Sandbox Code Playgroud)

看起来像这样:-

在此处输入图片说明