【问题标题】:Assigning to 'NSLineBreakMode' from incompatible type从不兼容的类型分配给“NSLineBreakMode”
【发布时间】:2013-02-07 14:33:39
【问题描述】:

将我的 xcode 4.5 更新到 4.6 后 ....

lblMyLable.lineBreakMode = UILineBreakModeWordWrap;
textFieldRounded1.textAlignment = UITextAlignmentLeft;

停止工作并显示不兼容的错误...它们在 xcode 更新前两天运行良好。

P.S:- lblMyLable 是一个 UILabel & textFieldRounded1 是一个 UITextField

我使用的是 6.1 IOS sdk

【问题讨论】:

  • 已弃用。人们总是认为平台供应商在拿他们的弃用警告开玩笑...... :)

标签: iphone ios uilabel xcode4.6


【解决方案1】:

在 iOS 6 中你需要使用 NSLineBreakByWordWrapping。 而不是:

lblMyLable.lineBreakMode = UILineBreakModeWordWrap;
textFieldRounded1.textAlignment = UITextAlignmentLeft;

用途:

lblMyLable.lineBreakMode = NSLineBreakByWordWrapping;
textFieldRounded1.textAlignment = NSTextAlignmentLeft;

详情

lineBreakMode

用于包装和截断标签文本的技术。 @property(nonatomic) NSLineBreakMode lineBreakMode;

讨论

如果您在 iOS 6 或更高版本中使用样式文本,请分配新值 到此属性会导致将换行模式应用于 attributesText 属性中的整个字符串。如果你想 仅将换行模式应用于文本的一部分,创建一个新的 属性字符串与所需的样式信息并将其关联 与标签。如果您不使用样式文本,则此属性 适用于 text 属性中的整个文本字符串。

此属性在正常绘图和案例中都有效 必须减小字体大小以适应标签的文本 边界框。这个属性被设置为 NSLineBreakByTruncatingTail 默认。

重要提示:如果此属性设置为导致文本换行的值 到另一行,设置 adjustsFontSizeToFitWidth 或 adjustsLetterSpacingToFitWidth 属性 是。

特别注意事项

在 iOS 5 及更早版本中,此属性的类型为 UILineBreakMode。 可用性

Available in iOS 2.0 and later.

NSLineBreakMode

这些常量指定当一行太长时会发生什么 容器。

enum {   
   NSLineBreakByWordWrapping = 0,   
   NSLineBreakByCharWrapping,
   NSLineBreakByClipping,    
   NSLineBreakByTruncatingHead,   
   NSLineBreakByTruncatingTail,    
   NSLineBreakByTruncatingMiddle
 };
 typedef NSUInteger NSLineBreakMo

常量

NSLineBreakByWordWrapping

Wrapping occurs at word boundaries, unless the word itself doesn’t fit on a single line.

Available in iOS 6.0 and later.

Declared in NSParagraphStyle.h.

NSLineBreakByCharWrapping

Wrapping occurs before the first character that doesn’t fit.

Available in iOS 6.0 and later.

Declared in NSParagraphStyle.h.

NSLineBreakByClipping

Lines are simply not drawn past the edge of the text container.

Available in iOS 6.0 and later.

Declared in NSParagraphStyle.h.

NSLineBreakByTruncatingHead

The line is displayed so that the end fits in the container and the missing text at the beginning of the line is indicated by an

省略号字形。虽然此模式适用于多行文本,但它是 更常用于单行文本。

Available in iOS 6.0 and later.

Declared in NSParagraphStyle.h.

NSLineBreakByTruncatingTail

The line is displayed so that the beginning fits in the container and the missing text at the end of the line is indicated by an

省略号字形。虽然此模式适用于多行文本,但它是 更常用于单行文本。

Available in iOS 6.0 and later.

Declared in NSParagraphStyle.h.

NSLineBreakByTruncatingMiddle

The line is displayed so that the beginning and end fit in the container and the missing text in the middle is indicated by an

省略号字形。虽然此模式适用于多行文本,但它是 更常用于单行文本。

Available in iOS 6.0 and later.

Declared in NSParagraphStyle.h.

详情请查看UILabel Class。 还要检查 UITextField Class 以获取 NSTextAlignment 值和详细信息。

【讨论】:

  • 另外,UITextAlignmentLeft 已替换为 NSTextAlignmentLeft。
【解决方案2】:

它们在 iOS 6 中都已被弃用;

UILineBreakModeWordWrap 已替换为 NSLineBreakByWordWrapping。

UITextAlignmentLeft 已替换为 NSTextAlignmentLeft

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-23
    • 2016-02-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多