2011-03-02 75 views

回答

11

嘗試

[buttonLeft.titleLabel setLineBreakMode:NSLineBreakByWordWrapping]; 
+0

哇,這工作......非常感謝響應!.... .. :) – devsri 2011-03-02 13:20:38

1

可以嘗試以下。它有點長,但我認爲它會工作:

//我們只想添加我們的自定義標籤一次;只有第一通應歸零 UILabel titleLabel =(UILabel)[self viewWithTag:TITLE_LABEL_TAG];

if (!titleLabel) 
{ 
    // no custom label found (1st pass), we will be creating & adding it as subview 
    titleLabel = [[UILabel alloc] initWithFrame:titleRect]; 
    [titleLabel setTag:TITLE_LABEL_TAG]; 

    // make it multi-line 
    [titleLabel setNumberOfLines:0]; 
    [titleLabel setLineBreakMode:UILineBreakModeWordWrap]; 

    // title appearance setup; be at will to modify 
    [titleLabel setBackgroundColor:[UIColor clearColor]]; 
    [titleLabel setFont:[self font]]; 
    [titleLabel setShadowOffset:CGSizeMake(0, 1)]; 
    [titleLabel setTextAlignment:UITextAlignmentCenter]; 

    [self addSubview:titleLabel]; 
    [titleLabel release]; 
} 

// finally, put our label in original title view's state 
[titleLabel setText:title]; 
[titleLabel setTextColor:titleColor]; 
[titleLabel setShadowColor:titleShadowColor]; 

// and return empty rect so that the original title view is hidden 
return CGRectZero; 

}

+0

UIButton已經在裏面定製了titleLabel,所以你不需要創建另一個 – Vladimir 2011-03-02 13:13:44

10

對於UILabel,相應的常量是現在NSLineBreakByWordWrapping(而不是UILineBreakModeWordWrap):

titleLabel.lineBreakMode = NSLineBreakByWordWrapping; 
0

只是檢查出並更換這些枚舉。

在iOS6的的previos是: - enter image description here

從iOS 6中,它是: -

enter image description here

相關問題