不推荐使用setLineBreakMode警告

时间:2011-03-02 12:39:47

标签: xcode uibutton

使用

时,我收到了弃用方法的警告
[buttonLeft setLineBreakMode:UILineBreakModeWordWrap];

这种方法还有其他替代品吗?

4 个答案:

答案 0 :(得分:11)

[buttonLeft.titleLabel setLineBreakMode:NSLineBreakByWordWrapping];

答案 1 :(得分:10)

对于UILabel,相应的常量现在为NSLineBreakByWordWrapping(而不是UILineBreakModeWordWrap):

titleLabel.lineBreakMode =  NSLineBreakByWordWrapping;

答案 2 :(得分: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;

}

答案 3 :(得分:0)

请检查并更换这些枚举。

在之前的ios 6中是: - enter image description here

从IOS 6开始: -

enter image description here