UIButton标题中的折线 [英] Breakline in UIButton title
问题描述
是显示的地址.我的问题是地址很长,我如何才能在按钮标题的两个变量之间插入换行符?
in the following button is an address showed. My problem is the addresses are very long and how can i get between the two variables in the title of the button an breakline??
NSString *sitz = map.kordinate.herkunft;
NSString *strasse = map.kordinate.strasse;
NSString *strasseMitKomma = [strasse stringByAppendingString:@","];
NSString *fertigesSitzFeld = [strasseMitKomma stringByAppendingString:sitz];
UIButton *firmensitz = [UIButton buttonWithType:UIButtonTypeRoundedRect];
折线必须在strasseMitKomma和sitz之间?
the breakline must be between strasseMitKomma and sitz??
感谢您的帮助
推荐答案
您必须在UIButton内配置UILabel以支持多行.
您可以这样做:
You must configure the UILabel inside the UIButton to support multiple line.
You can do it like this:
NSString *address;
address = [NSString stringWithFormat:@"%@,\n%@", @"street name", @"city name"]; // Note the \n after the comma, that will give you a new line
addressButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[addressButton.titleLabel setLineBreakMode:UILineBreakModeWordWrap]; // Enabling multiple line in a UIButton by setting the line break mode
[addressButton.titleLabel setTextAlignment:UITextAlignmentCenter];
[addressButton setTitle:address forState:UIControlStateNormal];
顺便说一句,您不需要那么多NSString变量.您可以将新字符串的结果放入已在使用的NSString变量中.
看看我答案的第一行中的方法stringWithFormat.阅读
By the way, you don't need so many NSString variables. You could have put the result of the new string in the NSString variable you were already using.
Have a look at the method stringWithFormat in the first line of my answer. Read the NSString documentation for more detail.
这篇关于UIButton标题中的折线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!