views:

171

answers:

2

Hello people, 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];

the breakline must be between strasseMitKomma and sitz??

thank you for helping

+1  A: 

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];

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.

PS: It's a good practice to use english variable names in your code. It makes it easier to share your code with your peers.

Guillaume
A: 

Hello guillaume,

thank you for your great help and you tips about english variable names!

Marco
You are welcome.Just a tip: Instead of posting a new answer, you should have commented on my answer.And if you are happy with it, you should mark it as accepted so other people stop to look at it.
Guillaume