2013-09-25 71 views
1

快速的問題,任何方式對齊已啓用Sizetofit爲UITextField?對右邊說?的UITextView SizetoFit右對齊中的UITableView

我有一個聊天對話窗口(的UITableView),並使用Sizetofit來幫助創建用於我的實際消息中的那些「泡沫」類型的對話(圖片=>Picture of my Conversation Chat Window, where the UITextField, MessageLabel has size to fit, but does not align RIGHT, for the user who is currently signed in.

任何幫助將大大可以理解,得到這些氣泡向右:-)

這裏是一個準系統片段....

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

{ 
static NSString *cellIdentifier = @"HistoryCell"; 
MessageCustomCellCell *cell = (MessageCustomCellCell *)[self.tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
if (cell == nil) { 
    cell.messageLabel.layer.cornerRadius = 9; 
    cell.messageLabel.clipsToBounds = YES; 
} 

NSSortDescriptor *ratingsSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:YES]; 
NSArray *sortedRows = [_tableData sortedArrayUsingDescriptors:[NSArray arrayWithObject:ratingsSortDescriptor]]; 
_tableData = sortedRows; 
NSDictionary *item = [_tableData objectAtIndex:[indexPath row]]; 


// loggedInUser 
if ([[item objectForKey:@"fromuser"] isEqualToString:loggedInUser]) { 

    cell.messageLabel.text = [item objectForKey:@"message"]; 
    cell.messageLabel.backgroundColor = [UIColor greenColor]; 
    cell.messageLabel.frame = CGRectMake(10, 25, 246, cell.messageLabel.contentSize.height); 
    [cell.messageLabel sizeToFit]; 

} else { 
// MESSAGE IS FRIEND OF THE PERSON SIGNED IN 
    cell.messageLabel.text = [item objectForKey:@"message"]; 
    cell.messageLabel.backgroundColor = [UIColor redColor]; 
    cell.messageLabel.frame = CGRectMake(65, 25, 250, cell.messageLabel.contentSize.height); 
    [cell.messageLabel sizeToFit]; 

} 

我想一個辦法是找出文本的實際寬度,或指望它,並調整和位置相應地,但不是確定如何。

謝謝!

+0

嘿,Knitsu!我正在嘗試自己聊天,現在也遇到同樣的問題。你有沒有解決它? – user1563544

回答

0

這是我的例子。

(void)initWithMessage:(NSString*)message { 
    [self.messageView setText:message]; 
    self.messageView.textColor = [UIColor whiteColor]; 

    [self.messageView sizeToFit]; 

    CGRect myFrame = self.messageView.frame; 
    myFrame.origin.x = self.frame.size.width - myFrame.size.width; 
    [self.messageView setFrame:myFrame]; 
}