zoukankan      html  css  js  c++  java
  • IOS之TextView属性设置

    UIFontDescriptor *bodyFontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleBody];
        self.textView.font = [UIFont fontWithDescriptor:bodyFontDescriptor size:0];
     
        self.textView.textColor = [UIColor blackColor];
        self.textView.backgroundColor = [UIColor whiteColor];
        self.textView.scrollEnabled = YES;
     
        // Let's modify some of the attributes of the attributed string.
        // You can modify these attributes yourself to get a better feel for what they do.
        // Note that the initial text is visible in the storyboard.
        NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithAttributedString:self.textView.attributedText];
     
        NSString *text = self.textView.text;
     
        // Find the range of each element to modify.
        NSRange boldRange = [text rangeOfString:NSLocalizedString(@"bold", nil)];
        NSRange highlightedRange = [text rangeOfString:NSLocalizedString(@"highlighted", nil)];
        NSRange underlinedRange = [text rangeOfString:NSLocalizedString(@"underlined", nil)];
        NSRange tintedRange = [text rangeOfString:NSLocalizedString(@"tinted", nil)];
     
        // Add bold.
        UIFontDescriptor *boldFontDescriptor = [self.textView.font.fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold];
        UIFont *boldFont = [UIFont fontWithDescriptor:boldFontDescriptor size:0];
        [attributedText addAttribute:NSFontAttributeName value:boldFont range:boldRange];
     
        // Add highlight.
        [attributedText addAttribute:NSBackgroundColorAttributeName value:[UIColor aapl_applicationGreenColor] range:highlightedRange];
     
        // Add underline.
        [attributedText addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:underlinedRange];
     
        // Add tint.
        [attributedText addAttribute:NSForegroundColorAttributeName value:[UIColor aapl_applicationBlueColor] range:tintedRange];
     
        // Add an image attachment.
        NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
        UIImage *image = [UIImage imageNamed:@"text_view_attachment"];
        textAttachment.image = image;
        textAttachment.bounds = CGRectMake(0, 0, image.size.width, image.size.height);
     
        NSAttributedString *textAttachmentString = [NSAttributedString attributedStringWithAttachment:textAttachment];
        [attributedText appendAttributedString:textAttachmentString];
     
        self.textView.attributedText = attributedText;
  • 相关阅读:
    RHEL6 kernel bug在hadoop上的测试
    Mapreduce报错:Split metadata size exceeded 10000000
    HDFS超租约异常总结(org.apache.hadoop.hdfs.server.namenode.LeaseExpiredException)
    zookeeper ACL使用
    通过Hadoop jmx收集Namenode,Jobtracker相关信息
    FFmpeg + nginx+asp.net实现网络摄像头RTSP视频流WEB端在线播放功能
    JQ+asp.net实现文件上传的断点续传功能
    freemaker模板引擎使用详解
    nginx配置详解
    MySQL数据库分页查询,Oracle数据库分页查询,SqlServer数据库分页
  • 原文地址:https://www.cnblogs.com/wcLT/p/4745857.html
Copyright © 2011-2022 走看看