ios - UITextView contentInset 不工作

标签 ios objective-c ios6 uitextview uiedgeinsets

我在 UITextView 中显示文本。我需要对文本应用一些填充。当我将值(value)用于最高职位时,它正在工作。如果我将值用于其他位置,则它不起作用。

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

最佳答案

对于 iOS7 使用 textContainerInset

@property(nonatomic, assign) UIEdgeInsets textContainerInset NS_AVAILABLE_IOS(7_0);

对于 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;
}

根据您的代码,您只设置顶部插图但是如果您希望设置所有侧面,则必须像下面这样设置内容插图:-

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

看起来像这样:-

enter image description here

关于ios - UITextView contentInset 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22935277/

相关文章:

ios - 边界更改时无法阻止 UITableView 移动

ios - 删除应用程序时,iOS6 模拟器是否存在错误?

ios - 使用 GPUImagePoissonBlendFilter 进行混合

ios - 使用 View Controller Containment 的缺点

ios - objective-c 社会/社会.h 未找到

objective-c - 在 UIImage 上使用 UIActivityViewController 时,有没有办法指定图像格式?

iphone - 允许用户在 iCloud 不可用时编辑/查看现有文档

ios - Swift:带有异步 Web 任务的事件指示器

ios - 使用 NSURLSession UploadTask 暂停、恢复、取消上传任务

ios - 如何关闭 ios 中的 Popover View