簡體   English   中英

UIButton頭銜的Breakline

[英]Breakline in UIButton title

在下面的按鈕是顯示的地址。 我的問題是地址很長,我怎么能在按鈕標題中的兩個變量之間得到一個斷裂線?

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之間?

感謝您的幫助

您必須在UIButton中配置UILabel以支持多行。
你可以這樣做:

 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。 閱讀NSString文檔以獲取更多詳細信息。

它適用於iOS9。

[_butNoReceipt.titleLabel setLineBreakMode:NSLineBreakByCharWrapping];
[_butNoReceipt.titleLabel setTextAlignment:NSTextAlignmentCenter];
[_butNoReceipt setTitle:btnTest forState:UIControlStateNormal];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM