zoukankan      html  css  js  c++  java
  • iOS -- 不可编辑的UITextView 自动调整高度

         _textView  = [[UITextView alloc] initWithFrame:CGRectMake(13, 10, UIScreenWidth-26, 20)];
            [self.contentView addSubview:_textView];
            _textView.textColor = UIColorFromRGB(0x111111);
            _textView.font = [UIFont systemFontOfSize:16];
            _textView.editable = NO;
            _textView.backgroundColor = [UIColor yellowColor];
            //_textView.autoresizingMask = UIViewAutoresizingFlexibleHeight;//相对于父视图不会改变属性
            _textView.textContainer.lineFragmentPadding = 0;
            _textView.textContainerInset = UIEdgeInsetsZero;
          [self textViewDidChange:_textView];
    
    
    //不可编辑的UITextView 自动调整高度
    - (void)textViewDidChange:(UITextView *)textView{
        CGRect frame = textView.frame;
        NSDictionary *attri = @{NSFontAttributeName:textView.font};
        CGSize size = [textView.text boundingRectWithSize:CGSizeMake(280, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:attri context:nil].size;
        
        frame.size.height = size.height > 1 ? size.height : 64;
        textView.frame = frame;
        
        //文本居中
        CGRect textFrame = [[textView layoutManager] usedRectForTextContainer:[textView textContainer]];
        CGFloat offsetY = (textView.frame.size.height - textFrame.size.height)/2;
        textView.textContainerInset = UIEdgeInsetsMake(offsetY, 0, 0, 0);
    }
  • 相关阅读:
    docker2核 elasticsearch卡死
    spring cloud config
    App网关Zuul
    spring Ribon
    spring Feign声明式服务消费(Ribbon Hystrix )
    spring Hystrix
    spring cloud 整体介绍
    springbean 生命周期
    xml六种解析方式
    jdk8中的forEach使用return执行下一次遍历
  • 原文地址:https://www.cnblogs.com/qiyiyifan/p/8017147.html
Copyright © 2011-2022 走看看