Ada masalah, perlu menetapkan beberapa teks ke judul UIButton. Telah menyetel mode jeda baris tombol ke NSLineBreakByCharWrapping sehingga string hanya dipisahkan oleh karakter di akhir setiap baris. Tetapi saya perlu menyisipkan tanda hubung di akhir baris untuk menunjukkan kesinambungan kata. Inilah yang saya coba -
// 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];
Ini adalah jarak terdekat yang bisa saya dapatkan.
Bantuan apa pun akan sangat dihargai.
UILabel
. - person TheTiger   schedule 06.08.2013