添加导航栏气泡

2017-08-07  本文已影响0人  eb7a9dac29d0

- (void)bubbleView:(NSString *)text{

NSDictionary * attribute = @{NSFontAttributeName:[UIFont systemFontOfSize:Font(12)]};

CGSize size = [text boundingRectWithSize:CGSizeMake(MTScreenWidth - 20, MAXFLOAT) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;

//背景图片

UIImage * bubble = [UIImage imageNamed:@"icon_left_chat_bubble"];

UIImageView * bubbleImageView = [[UIImageView alloc] initWithImage:[bubble resizableImageWithCapInsets:UIEdgeInsetsMake(25, 30, 10, 10)]];

//添加文本信息

UILabel *bubbleText = [[UILabel alloc] init];

bubbleText.backgroundColor = [UIColor clearColor];

bubbleText.font = [UIFont systemFontOfSize:Font(12)];

bubbleText.numberOfLines = 0;

bubbleText.lineBreakMode = NSLineBreakByCharWrapping;

bubbleText.text = text;

[self.view addSubview:bubbleText];

//    [self.navigationController.navigationBar.topItem setTitleView:self.segmentView];

[bubbleText mas_makeConstraints:^(MASConstraintMaker *make) {

make.top.mas_equalTo(-10);

make.left.mas_equalTo(15);

make.size.mas_equalTo(CGSizeMake(size.width, size.height + 10));

}];

[self.view addSubview:bubbleImageView];

[bubbleImageView mas_makeConstraints:^(MASConstraintMaker *make) {

make.left.and.top.mas_equalTo(-10);

make.size.mas_equalTo(CGSizeMake(size.width + 15, size.height + 10));

}];

}

上一篇 下一篇

猜你喜欢

热点阅读