UIButton ที่มีข้อความสองบรรทัดในชื่อเรื่อง (numberOfLines = 2)
ฉันกำลังพยายามทำให้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 …