xcode 不推荐使用 setLineBreakMode 警告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5167571/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:21:31  来源:igfitidea点击:

Deprecated setLineBreakMode Warning

xcodeuibutton

提问by devsri

I am getting a warning of deprecated method when using

我在使用时收到不推荐使用的方法的警告

[buttonLeft setLineBreakMode:UILineBreakModeWordWrap];

Is there any other substitute of this method?

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

回答by Vladimir

try

尝试

[buttonLeft.titleLabel setLineBreakMode:NSLineBreakByWordWrapping];

回答by Zimbardo

For UILabel, the appropriate constant is now NSLineBreakByWordWrapping(instead of UILineBreakModeWordWrap):

对于UILabel,适当的常数现在是NSLineBreakByWordWrapping(而不是UILineBreakModeWordWrap):

titleLabel.lineBreakMode =  NSLineBreakByWordWrapping;

回答by Dipanjan Dutta

can try the the following. it's bit long but i think it will work:

可以尝试以下方法。它有点长,但我认为它会起作用:

// we only want to add our custom label once; only 1st pass shall return nil UILabel titleLabel = (UILabel)[self viewWithTag:TITLE_LABEL_TAG];

// 我们只想添加我们的自定义标签一次;只有第一遍应返回 nil 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;

}

}

回答by Gaurav

Just check out and replace these enums.

只需检查并替换这些枚举即可。

In the previos of ios6 was:- enter image description here

在 ios6 之前的版本是:- 在此处输入图片说明

From IOS 6 it is:-

从 IOS 6 开始,它是:-

enter image description here

在此处输入图片说明