ฉันกำลังพยายามทำให้UIButtonมีข้อความสองบรรทัดใน titleLabel นี่คือรหัสที่ฉันใช้:
UIButton *titleButton = [[UIButton alloc] initWithFrame:CGRectMake(15, 10, frame.size.width-100, 100)];
titleButton.titleLabel.font = [UIFont boldSystemFontOfSize:24.0];
[titleButton setTitle:@"This text is very long and should get truncated at the end of the second line" forState:UIControlStateNormal];
titleButton.titleLabel.lineBreakMode = UILineBreakModeTailTruncation;
titleButton.titleLabel.numberOfLines = 2;
[self addSubview:titleButton];
เมื่อฉันลองสิ่งนี้ข้อความจะปรากฏในบรรทัดเดียวเท่านั้น ดูเหมือนว่าวิธีเดียวที่จะประสบความสำเร็จมากกว่าหนึ่งบรรทัดของข้อความในUIButton.titleLabelคือการตั้งค่าและการใช้งานnumberOfLines=0 UILineBreakModeWordWrapแต่ไม่ได้รับประกันว่าข้อความจะมีสองบรรทัด
อย่างไรก็ตามการใช้แบบธรรมดาUILabelจะได้ผล:
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, frame.size.width-100, 100)];
titleLabel.font = [UIFont boldSystemFontOfSize:24.0];
titleLabel.text = @"This text is very long and should get truncated at the end of the second line";
titleLabel.numberOfLines = 2;
titleLabel.lineBreakMode = UILineBreakModeTailTruncation;
[self addSubview:titleLabel];
ไม่มีใครรู้วิธีทำให้UIButtonงานมีสองบรรทัด? เป็นทางออกเดียวในการสร้างแยกUILabelเพื่อเก็บข้อความและเพิ่มเป็นมุมมองย่อยของปุ่มหรือไม่
