美文网首页
添加导航栏气泡

添加导航栏气泡

作者: eb7a9dac29d0 | 来源:发表于2017-08-07 14:24 被阅读0次

    - (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));

    }];

    }

    相关文章

      网友评论

          本文标题:添加导航栏气泡

          本文链接:https://www.haomeiwen.com/subject/qpfalxtx.html