【问题标题】:Add Custom label in JSQViewMessageViewController iOS在 JSQViewMessageViewController iOS 中添加自定义标签
【发布时间】:2016-01-10 21:13:33
【问题描述】:

我想在每个单元格中添加一个自定义标签(带有时间戳)以及在 JSQMessageViewController 中添加一个图像(用于警告消息)。我已经在使用底部标签和顶部标签。但我无法得到我想要的结果。 The image is a reference of what I would like it to look like

【问题讨论】:

    标签: ios objective-c iphone ios7 jsqmessagesviewcontroller


    【解决方案1】:
    UIImage *bubbleImage = [UIImage imageNamed:@"Commentbox_right.png"];
            UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(textFrame.origin.x-2, textFrame.origin.y-2, textFrame.size.width+4 , textFrame.size.height+7)];
            imgView.image= [bubbleImage stretchableImageWithLeftCapWidth:bubbleImage.size.width/2-5 topCapHeight:bubbleImage.size.height/2];
            [cell addSubview:imgView];
            [cell bringSubviewToFront:txtViewMessage];
    
            UILabel *lblTimeStamp = [[UILabel alloc]initWithFrame:CGRectMake(textFrame.origin.x+2, imgView.frame.size.height+imgView.frame.origin.y, 90, 10)];
            [lblTimeStamp setText:message.dateTime];//set time here
            [lblTimeStamp setFont:FONT_300_LIGHT(7)];
            [lblTimeStamp setTextColor:GET_COLOR_WITH_RGB(129,129,129, 1)];
            [lblTimeStamp setTextAlignment:NSTextAlignmentLeft];
            [lblTimeStamp setBackgroundColor:[UIColor  clearColor]];
            [cell addSubview:lblTimeStamp];
    

    【讨论】:

    • 感谢您的回答。但我需要在 JSQMessageviewcontroller 的委托方法中使用。
    【解决方案2】:

    抱歉,我没有太多时间查看它。但是您可以再次将该图像添加到同一消息气泡 xib 中,并根据您的需要添加约束。 Try this xib

    【讨论】:

      【解决方案3】:

      如何在 JSQMessageviewcontroller 中添加自定义标签是...
      我在 ViewDidLoad 之前声明 Label 文本。

       // Add Text Label
      let myLabel: UILabel = {
          let lb = UILabel()
          lb.translatesAutoresizingMaskIntoConstraints = false
          lb.textAlignment = .center
          lb.numberOfLines = 1
          lb.textColor = UIColor.white
          lb.font=UIFont.systemFont(ofSize: 22)
          lb.backgroundColor = UIColor(red: 0.0/255.0, green:70.0/255.0, blue:110.0/255.0, alpha:1)
          lb.text = NSLocalizedString("No Notification", comment: "")
      
          return lb
      }()
      


      并在 viewDidiLoad 中添加此代码或在任何您喜欢的地方调用。

       self.view.addSubview(myLabel)
       setUpMyLabel() 
      

      这就是我在应用中添加自定义标签的方式。希望这会帮助你。 :)

      【讨论】:

        猜你喜欢
        • 2021-02-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-25
        相关资源
        最近更新 更多