multiple line of UILabel, is it possible?
I've read through SO and it seems that it is possible, however I tried it and it didn't work out:
UILabel * detailed_label = [[UILabel alloc] initWithFrame:CGRectMake(50, labelSize.height + 30, textSize.width + 开发者_StackOverflow中文版5, textSize.height + 5)];
detailed_label.backgroundColor = [UIColor clearColor];
detailed_label.textColor = [UIColor whiteColor];
detailed_label.font = [UIFont systemFontOfSize:12];
detailed_label.text = self.detailed;
detailed_label.numberOfLines = 0;
detailed_label.lineBreakMode = UILineBreakModeWordWrap;
detailed_label.shadowColor = [UIColor darkGrayColor];
detailed_label.shadowOffset = CGSizeMake(1, 1);
CGSize detailedLabelSize = [self.detailed sizeWithFont:label.font constrainedToSize:CGSizeMake(280.0f, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
UIButton *v = [UIButton buttonWithType:UIButtonTypeCustom];
v.frame = CGRectMake(0, 0, textSize.width + avatar_image.size.width + 10, labelSize.height + detailedLabelSize.height + 30);
//label.center = CGPointMake(v.frame.size.width / 2, v.frame.size.height / 2);
[v addSubview:detailed_label];
Am I doing something wrong?
As your working with a UIButton. You can take advantage of the label already on it, use button.titleLabel
to access it.
Next set button.titleLabel.minimumFontSize
and button.titleLabel.font
. Then set button.titleLabel.numberOfLines
> 1.
If you need to find out how high to make your label. Use [self.detailed sizeWithFont:fontWithMinimumFontSize constrainedToSize:CGSizeMake(width, DBL_MAX) lineBreakMode:UILineBreakModeWordWrap].height + PADDING;
精彩评论