我正在开发一个简单的报价生成器的个人项目。
用户可以将喜欢的引号保存到列表中,并且在列表视图中我希望UILabel响应内容的大小(有些引号很短,有些引用很长 - 看起来有点奇怪)。
非常感谢任何帮助。
UILabel *favouriteLabel;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
favouriteLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, -10, 400, 140)];
}else {
favouriteLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, -20, 180, 130)];
}
favouriteLabel.backgroundColor = [UIColor clearColor];
favouriteLabel.text = [self.arrayFromFile objectAtIndex:indexPath.row];
NSLog(@"Row alloc %d", indexPath.row);
NSLog(@"Load label %@", favouriteLabel.text);
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
favouriteLabel.font = [UIFont fontWithName: @"Eras Bold ITC" size: 18];
}else if([GUIHelper isPhone5]){
favouriteLabel.font = [UIFont fontWithName: @"Dosis-Medium" size: 15];
}
else
favouriteLabel.font = [UIFont fontWithName: @"Dosis-Medium" size: 15];
favouriteLabel.textColor = [UIColor colorWithRed:68.0/255.0 green:68.0/255.0 blue:68.0/255.0 alpha:1];
favouriteLabel.textAlignment = UITextAlignmentCenter;
favouriteLabel.numberOfLines = 0;
favouriteLabel.center = CGPointMake(cell.center.x - 40, cell.center.y + 20);
favouriteLabel.tag = 900;
[cell.contentView addSubview:favouriteLabel];
UIImage *lineImg = [UIImage imageNamed:@"quote-divider@2x.png"];
CGRect lineImageFrame;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
lineImageFrame = CGRectMake(0, 120, lineImg.size.width, lineImg.size.height);
}else{
lineImageFrame = CGRectMake(0, 62, lineImg.size.width * 0.9, 0.8*lineImg.size.height);
}
UIImageView *lineImageView = [[UIImageView alloc] initWithFrame:lineImageFrame];
lineImageView.image = lineImg;
lineImageView.center = CGPointMake(cell.center.x - 40, lineImageView.center.y + 35);