0

Context:

I am building a chat app, I used code from apple sample.

It looks exactly like the native message app. My issue is on the iPad version I am implementing.

Here's an image:

enter image description here

As you can see in the image, I need it the righ ballon to be on the right edge of the screen

I track down the code, and I narrow down the block of code that needs tweaking.

// Comput the X,Y origin offsets
CGFloat xOffsetLabel;
CGFloat xOffsetBalloon;
CGFloat yOffset;

if (TRANSCRIPT_DIRECTION_SEND == transcript.direction) {//
    // Sent messages appear or right of view
    xOffsetLabel = 320 - labelSize.width - (BALLOON_WIDTH_PADDING / 2) - 3;
    xOffsetBalloon = 320 - balloonSize.width;
    yOffset = BUFFER_WHITE_SPACE / 2;
    _nameLabel.text = @"";
    // Set text color
    _messageLabel.textColor = [UIColor whiteColor];
    // Set resizeable image
    _balloonView.image = [self.balloonImageRight resizableImageWithCapInsets:_balloonInsetsRight];
}
else {
    // Received messages appear on left of view with additional display name label
    xOffsetBalloon = 0;
    xOffsetLabel = (BALLOON_WIDTH_PADDING / 2) + 3;
    yOffset = (BUFFER_WHITE_SPACE / 2) + nameSize.height - NAME_OFFSET_ADJUST;
    if (TRANSCRIPT_DIRECTION_LOCAL == transcript.direction) {
        _nameLabel.text = @"user";
    }
    else {
        _nameLabel.text = @"Admin"; //nameText;
    }
    // Set text color
    _messageLabel.textColor = [UIColor darkTextColor];
    // Set resizeable image
    _balloonView.image = [self.balloonImageLeft resizableImageWithCapInsets:_balloonInsetsLeft];
}

// Set the dynamic frames
_messageLabel.frame = CGRectMake(xOffsetLabel, yOffset + 5, labelSize.width, labelSize.height);
_balloonView.frame = CGRectMake(xOffsetBalloon, yOffset, balloonSize.width, balloonSize.height);
_nameLabel.frame = CGRectMake(xOffsetLabel - 2, 1, nameSize.width, nameSize.height);

Unfortunately my attempts to place green ballon to the right were unsuccessful(I can only more the content of the text to the right not the ballon itself). any idea ?

1 Answers1

2

Here:

xOffsetLabel = 320 - labelSize.width - (BALLOON_WIDTH_PADDING / 2) - 3;
xOffsetBalloon = 320 - balloonSize.width;

320 is the width of the iPhone screen. That needs to be changed to the width of the iPad (either 1024 or 768 depending on the orientation).

Of course your view also needs to be as wide as the iPad screen, so make sure that that's resized too.

Tim

tarmes
  • 15,366
  • 10
  • 53
  • 87