新浪微博客户端(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:@"%@\n%@",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

最终效果:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值