iphone - 从不兼容类型分配给 'NSLineBreakMode'

标签 iphone ios uilabel xcode4.6

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

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

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

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

我使用的是6.1 IOS sdk

最佳答案

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

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

用途:

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

详细信息

lineBreakMode

The technique to use for wrapping and truncating the label’s text. @property(nonatomic) NSLineBreakMode lineBreakMode;

Discussion

If you are using styled text in iOS 6 or later, assigning a new value to this property causes the line break mode to be applied to the entirety of the string in the attributedText property. If you want to apply the line break mode to only a portion of the text, create a new attributed string with the desired style information and associate it with the label. If you are not using styled text, this property applies to the entire text string in the text property.

This property is in effect both during normal drawing and in cases where the font size must be reduced to fit the label’s text in its bounding box. This property is set to NSLineBreakByTruncatingTail by default.

Important: If this property is set to a value that causes text to wrap to another line, it is a programmer error to set either the adjustsFontSizeToFitWidth or adjustsLetterSpacingToFitWidth property to YES.

Special Considerations

In iOS 5 and earlier, the type of this property was UILineBreakMode. Availability

Available in iOS 2.0 and later.

NSLineBreakMode

These constants specify what happens when a line is too long for its container.

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

Constants

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

ellipsis glyph. Although this mode works for multiline text, it is more often used for single line text.

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

ellipsis glyph. Although this mode works for multiline text, it is more often used for single line text.

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

ellipsis glyph. Although this mode works for multiline text, it is more often used for single line text.

Available in iOS 6.0 and later.

Declared in NSParagraphStyle.h.

请查看UILabel Class更多细节。 另请检查UITextField Class有关 NSTextAlignment 值和详细信息。

关于iphone - 从不兼容类型分配给 'NSLineBreakMode',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14753579/

相关文章:

iphone - 静态库中字符串的本地化

ios - 高分重置为 0

ios - UILabel 和 UIActivityIndi​​catorView 以 UITableView 的可见区域为中心

ios - 如何以编程方式在 UIScrollView 中添加 UILabel?

javascript - iPhone Web 应用程序的最佳客户端数据存储?

iphone - 动画 UIViews 以获得交叉淡入淡出效果效果不佳

iphone - 自定义 UILabel 创建以避免本地化问题

ios - iOS 8 中的自定义状态栏

android - Cordova:如何在没有 https 的情况下使 GPS getlocation 工作?

ios - 超出 UILabel 范围的 UILabel 动画