zoukankan      html  css  js  c++  java
  • 新浪微博客户端(35)-使用NSMutableAttributedString实现多行文本的效果

    DJComposeViewController.m

    import "DJComposeViewController.h"
    #import "DJAccountTool.h"
    
    
    @implementation DJComposeViewController
    
    
    
    
    - (void)viewDidLoad {
    
        [super viewDidLoad];
        [self initNavigationView];
        [self initInputView];
    
    }
    
    
    - (void)viewDidAppear:(BOOL)animated {
    
        [super viewDidAppear:animated];
         self.navigationItem.rightBarButtonItem.enabled = NO;
        
    }
    
    
    /** 初始化NavigationView */
    - (void)initNavigationView {
    
        self.view.backgroundColor = [UIColor whiteColor];
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStyleDone target:self action:@selector(finish)];
        
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"发送" style:UIBarButtonItemStylePlain target:self action:@selector(send)];
        
        
        
        
        UILabel *titleView = [[UILabel alloc] init];
        titleView.width = 200;
        titleView.height = 44;
        titleView.numberOfLines = 0; // 设置titleView 为多行显示
        titleView.textAlignment = NSTextAlignmentCenter;
        
        DJAccount *account = [DJAccountTool account];
        NSString *nickName = account.screen_name;
        NSString *prefix = @"发微博";
        NSString *str = [NSString stringWithFormat:@"%@
    %@",prefix,nickName];
        NSRange nick_name_range = [str rangeOfString:nickName];
        NSRange prefix_range = [prefix rangeOfString:prefix];
        
        NSMutableAttributedString *titleStr = [[NSMutableAttributedString alloc] initWithString:str];
        [titleStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:nick_name_range];
        [titleStr addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:15] range:prefix_range];
        
        
        titleView.attributedText = titleStr;
        self.navigationItem.titleView = titleView;
        
    }
    
    
    
    /** 初始化输入区域 */
    - (void)initInputView {
    
        UITextView *inputView = [[UITextView alloc] init];
        inputView.frame = self.view.bounds;
        [self.view addSubview:inputView];
    
    }
    
    
    
    - (void)finish {
    
        [self dismissViewControllerAnimated:YES completion:nil];
        
    
    }
    
    
    /** 发微博 */
    - (void)send {
    
    
        
        
    }
    
    
    @end

    最终效果:

     

  • 相关阅读:
    使用dozermapper,处理不了LocalDateTime的映射问题:java.lang.NoSuchMethodException: java.time.LocalDateTime.<init>()
    mybatis-plus使用Wrapper自定义sql时出现错误:Invalid bound statement (not found)
    com.baomidou.mybatisplus.core.mapper 不存在
    python爬虫
    DRF源码系列分析
    python学习目录
    脚本加载django环境
    celery定时任务
    用脚本创建django-orm数据库表数据
    关于python很吊的一项技术!!!!!
  • 原文地址:https://www.cnblogs.com/yongdaimi/p/6099201.html
Copyright © 2011-2022 走看看