มีปัญหา จำเป็นต้องกำหนดข้อความให้กับชื่อเรื่องของ UIButton ตั้งค่าโหมดตัวแบ่งบรรทัดของปุ่มเป็น NSLineBreakByCharWrapping เพื่อให้สตริงถูกคั่นด้วยอักขระที่ท้ายแต่ละบรรทัดเท่านั้น แต่ฉันต้องใส่ยัติภังค์ที่ท้ายบรรทัดเพื่อแสดงความต่อเนื่องของคำ นี่คือสิ่งที่ฉันลอง -
// Initialize the button
titleButton.titleLabel.lineBreakMode = NSLineBreakByCharWrapping;
titleButton.titleLabel.backgroundColor = [UIColor yellowColor];
[titleButton.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:15]];
// Make the string here
NSMutableString *titleString = [[NSMutableString alloc] initWithString:@"abcdefghijklmnopqrs tuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"];
// Insert hyphens
int titleLength = [titleString length];
int hyphenIndex = 19;
while (hyphenIndex<titleLength) {
UniChar charatIndex = [titleString characterAtIndex:hyphenIndex];
if ((charatIndex - ' ') != 0) { // Check if its not a break bw two words
[titleString insertString:@"-" atIndex:hyphenIndex]; // else insert an hyphen to indicate word continuity
}
hyphenIndex += 19; //Since exactly 20 char are shown in single line of the button's label.
}
//Set the hyphenated title for the button
[titleButton setTitle:titleString forState:UIControlStateNormal];
[titleString release];
นี่คือสิ่งที่ใกล้เคียงที่สุดที่ฉันสามารถทำได้
ความช่วยเหลือใด ๆ ที่จะได้รับการชื่นชมอย่างมาก.
UILabel
แก่คุณ - person TheTiger   schedule 06.08.2013