UITextView 如何让第一行文字缩进一段距离

解决方案很简单 代码如下

CGFloat labelWidth =85.0;
UITextView  *textView= [[UITextView alloc]initWithFrame:CGRectMake(10, 100,KScreenWidth-20,100)];
textView.textAlignment=NSTextAlignmentLeft;
textView.textColor= [UIColor blackColor];
textView.backgroundColor= [UIColor clearColor];
self.addrssInfoTextView.font= [UIFontsystemFontOfSize:17];
UIBezierPath *bezi = [UIBezierPath bezierPathWithRect:CGRectMake(0,0, labelWidth+10,20)];
textView.textContainer.exclusionPaths=@[bezi];
textView.translatesAutoresizingMaskIntoConstraints=YES;
textView.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
[self.view addSubview:textView];
UILabel* label = [[UILabel alloc]initWithFrame:CGRectMake(0,5, labelWidth,24)];
label.text= @"左边文字";
label.textAlignment=NSTextAlignmentCenter;
label.textColor= [UIColor blackColor];
label.font= [UIFont systemFontOfSize:17];
[textView addSubview:label];

效果如下

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,653评论 25 709
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,223评论 4 61
  • 有几天没见着小毛孩了,今天见着小区里常溜达的刘大爷顺嘴问了句:“刘老,咱小区那狗哪儿去了?您见了吗?”“让物...
    燕刚阅读 4,088评论 5 4
  • 最近有一篇报道火遍了好友圈,听说国际上已经将中年的门槛由之前的1985年推导了1992年,只要是1992年之前出生...
    兮秒阅读 9,170评论 22 129
  • 陈可抒/文 如你所知,金榜题名是人生四大喜事之首,连「洞房花烛夜」都只能算是「小登科」。毕竟,远如科举,近如高考,...
    陈可抒阅读 4,189评论 0 3