मैं UIButtonइसके शीर्षकलेब में पाठ की दो पंक्तियाँ बनाने की कोशिश कर रहा हूँ । यह वह कोड है जिसका मैं उपयोग कर रहा हूं:
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टेक्स्ट को होल्ड करने के लिए एक अलग बनाने और बटन के उप-भाग के रूप में जोड़ने का एकमात्र समाधान है ?
