多线UILabel,有可能吗?

时间:2011-05-25 22:10:21

标签: iphone objective-c ipad uilabel

我已经阅读了SO,似乎有可能,但是我尝试了它并没有成功:

UILabel * detailed_label = [[UILabel alloc] initWithFrame:CGRectMake(50, labelSize.height + 30, textSize.width + 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];

我做错了吗?

1 个答案:

答案 0 :(得分:0)

当您使用UIButton时。您可以利用其上已有的标签,使用button.titleLabel来访问它。

接下来设置button.titleLabel.minimumFontSizebutton.titleLabel.font。然后设置button.titleLabel.numberOfLines> 1。

如果您需要了解制作标签的高度。使用[self.detailed sizeWithFont:fontWithMinimumFontSize constrainedToSize:CGSizeMake(width, DBL_MAX) lineBreakMode:UILineBreakModeWordWrap].height + PADDING;