Uitableview hücrelerinde metin etiketlerinin yüksekliğini hesaplamak için sabırsızlanıyorum. Boyut 7'nin ios 7 ile kullanımdan kaldırıldığını gördükten sonra, büyük harfleri uyguladık, ancak geri dönüş değerleri, etiketin içerdiği metin için doğru boyutta olması gerekenden daha küçüktü. Aynı zamanda sizetofit yöntemi de boşuna denedim.Boyutları doğru boyutta iade edilmiyor.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSDictionary *message = self.messages[indexPath.row];
UILabel *nameLabel = (UILabel *)[cell.contentView viewWithTag:1];
UILabel *messageContent = (UILabel *)[cell.contentView viewWithTag:3];
UIImageView *image = (UIImageView *)[cell.contentView viewWithTag:2];
messageContent.text = [message objectForKey:@"messageContent"];
NSString *content = [message objectForKey:@"messageContent"];
NSLog(@"Message: %@", content);
CGSize textSize = [content sizeWithAttributes:@{ NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Light" size:17.0]}];
messageContent.font = [UIFont fontWithName:@"HelveticaNue-Light" size:17.0];
CGRect messageFrame = messageContent.frame;
messageFrame.size = textSize;
messageContent.frame = messageFrame;
nameLabel.text = [message objectForKey:@"senderName"];
NSString *senderPicture = [message objectForKey:@"senderPicture"];
UIImage* myImage = [UIImage imageWithData:
[NSData dataWithContentsOfURL:
[NSURL URLWithString: senderPicture]]];
image.image = myImage;
image.layer.cornerRadius = 27.0;
image.layer.masksToBounds = YES;
//Configure the cell...
return cell;
}
Bu çalışır, ancak sadece ben için autolayout ayarladığınızda IB'de kapalı ve etiketleri yaptığım zaman hepsi uitableview hücrelerinde yerim yok – user2489946
içinde var. Bu cevap elio.d, sizin değil. http://stackoverflow.com/questions/19145078/ios-7-sizewithattributes-replacement-for-sizewithfontconstrainedtosize – Brave
@Brave başkalarının işlerini bu kadar gevşek yapıştırarak kopyalayın. Onun için uygun bir atıfta düzenledim, umarım Elio'ya daha fazla vade getirecektir. –