• 类似备忘录的文本 -- 设置行高和每一行的下划线


    #import "EHTextView.h"
    
    @implementation EHTextView
    
    - (instancetype)initWithFrame:(CGRect)frame
                          andText:(NSString *)mText
    {
        self = [super initWithFrame:frame];
    
        if (self)
        {
            NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    
            // 行间距
            paragraphStyle.lineHeightMultiple = 40;
            paragraphStyle.maximumLineHeight = 40;
            paragraphStyle.minimumLineHeight = 40;
            self.textContainerInset = UIEdgeInsetsMake(-10, 0, 0, 0);
            NSString *oneRowStr = [mText substringWithRange:NSMakeRange(0, [mText rangeOfString:@"
    "].location)];
            NSMutableAttributedString *prefixAttr = [[NSMutableAttributedString alloc] initWithString:mText];
            [prefixAttr addAttribute:NSFontAttributeName value:FZHei(17) range:NSMakeRange(0, mText.length)];
            [prefixAttr addAttribute:NSForegroundColorAttributeName value:ColorHui range:NSMakeRange(0, mText.length)];
            [prefixAttr addAttribute:NSFontAttributeName value:FZHei(17) range:NSMakeRange(0, oneRowStr.length)];
            [prefixAttr addAttribute:NSForegroundColorAttributeName value:ColorHuiHei range:NSMakeRange(0, oneRowStr.length)];
            [prefixAttr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, mText.length)];
            self.attributedText = prefixAttr;
    
            self.backgroundColor = [UIColor clearColor];
            self.userInteractionEnabled = NO;
        }
    
        return self;
    }
    
     
    - (void)drawRect:(CGRect)rect {
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetStrokeColorWithColor(context, HexRGB(0xd2d2d2).CGColor);
        CGContextSetLineWidth(context, 0.5f);
        CGContextBeginPath(context);
        CGFloat rowH = 40;
        NSUInteger numberOfLines =  (self.bounds.size.height - 15) / rowH;
        CGFloat baselineOffset = 0;
        for (int x = 1; x < numberOfLines + 1; x++) {
            CGContextSetStrokeColorWithColor(context, [UIColor lightGrayColor].CGColor);
            CGFloat lengthstest[] = {5,2};
            CGContextSetLineDash(context, 2, lengthstest,1);
            CGContextMoveToPoint(context, 2, rowH * x  + baselineOffset);
            CGFloat rowW = numberOfLines == x ? 35 : 0;
            CGContextAddLineToPoint(context, CGRectGetWidth(rect) - rowW, rowH * x + baselineOffset);
            CGContextStrokePath(context);
        }
    
        CGContextStrokePath(context);
    }
    @end
  • 相关阅读:
    mysql的查询、子查询及连接查询
    面向对象知识点续及单例模式
    PSR-2 编码风格规范
    PSR-1 基础编码规范
    博客园文章添加版权信息的方法
    微博第三方登陆接入流程
    使用EasyWechat快速开发微信公众号支付
    Git版本管理工具的使用
    E: Could not get lock /var/lib/apt/lists/lock
    ubuntu安装opencv
  • 原文地址:https://www.cnblogs.com/Milo-CTO/p/4633122.html
Copyright © 2020-2023  润新知