@interface HKZComposeViewController ()

@end

@implementation HKZComposeViewController

- (void)viewDidLoad {
    [super viewDidLoad];


    self.view.backgroundColor = [UIColor whiteColor];
    
    //设置导航栏的内容
    [self setupNav];
    
    //设置textview
    [self setupTextView];


}


- (void)setupTextView{


    HKZTextView *textView = [[HKZTextView alloc]init];
    textView.frame = self.view.bounds;
    textView.placeholder = @"听说下雨天音乐和巧克力更配duang";
    [self.view addSubview:textView];

}
//设置导航栏内容
- (void)setupNav{

    //设置返回按钮
    //self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTitle:@"返回" addTarget:self action:@selector(back)];
    //设置发送按钮
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"发送" style:UIBarButtonItemStylePlain target:self action:@selector(send)];
    
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTitle:@"发送" addTarget:self action:@selector(send)];
    
    //设置发送按钮的不可用状态
    self.navigationItem.rightBarButtonItem.enabled = NO;
    
    
    
    
    UILabel *label = [[UILabel alloc]init];
    //允许换行
    label.numberOfLines = 0;
    //设置文字居中
    label.textAlignment = NSTextAlignmentCenter;
    
    //设置中间标题
    NSString *preStr = @"发微博";
    //取出当前用户的昵称信息
    NSString *screen_name =  [HKZAccountTool account].screen_name;
    
    NSString *fullStr = nil;
    //判断是否存在用户名信息
    if (screen_name.length) {
        fullStr = [NSString stringWithFormat:@"%@\n%@",preStr,screen_name];
    }
    else{
    
        fullStr = [NSString stringWithFormat:@"%@",preStr];
    
    }
    
    
    
    //创建一个可变的设置字符串属性的字符串
    NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc]initWithString:fullStr];
    
    //首先取到preStr,设置他的属性
    NSRange preStrRange = NSMakeRange(0, preStr.length);
    //给attributeString设置属性
    [attributeString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:preStrRange];
    
    //取出screen_name的range
    NSRange screen_nameRange = [fullStr rangeOfString:screen_name];
    
#warning 这里最好进行判断,以后一用到range就要想到先判断在使用
    if (screen_nameRange.location != NSNotFound) {
        
        [attributeString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:screen_nameRange];
        [attributeString addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:screen_nameRange];
    }

    
    //设置label显示的带有属性的字符串
    label.attributedText = attributeString;
    //设置label的frame
    [label sizeToFit];
    
    self.navigationItem.titleView = label;

}

- (void)back{

    //NSLog(@"%s",__func__);
    [self dismissViewControllerAnimated:YES completion:nil];

}

- (void)send{

    NSLog(@"HKZComposeViewController.m ---发送消息");

}



@end
