//文字的字體 NSDictionary *attribute = @{NSFontAttributeName:[UIFont fontWithName:@"Heiti SC" size:15.0f]}; //將text轉化爲NSMutableAttributedString類型 NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:_titleLabel.text attributes:attribute]; //設置行間距 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; [paragraphStyle setLineSpacing:6.0f]; [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [_titleLabel.text length])]; //得到UILabel的size,其中,296和93是size的限定值 CGSize DateSize = [attributedString boundingRectWithSize:CGSizeMake(296, 93) options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil].size; //若是UILabel的寬度太寬的話 if (DateSize.width > 518.0f/2) { _titleLabel.size = CGSizeMake(296.0f, DateSize.height); _titleLabel.textAlignment = NSTextAlignmentLeft; _titleLabel.lineBreakMode = NSLineBreakByCharWrapping; _titleLabel.numberOfLines = 0; //不限定行數,自動換行 _titleLabel.attributedText = attributedString; }