ios - NSLineBreakMode 枚举和向后兼容性
<p><p>我需要我的应用支持 iOS 5+。从之前的 iOS 6 开始,枚举 <a href="https://developer.apple.com/library/ios/documentation/uikit/reference/UILabel_Class/Reference/UILabel.html#//apple_ref/occ/instp/UILabel/lineBreakMode" rel="noreferrer noopener nofollow"><code>lineBreakMode</code></a> <a href="https://developer.apple.com/library/ios/documentation/uikit/reference/UILabel_Class/Reference/UILabel.html#//apple_ref/occ/instp/UILabel/" rel="noreferrer noopener nofollow"><code>UILabel</code></a> 中的换行模式是 <a href="https://developer.apple.com/library/ios/documentation/uikit/reference/NSString_UIKit_Additions/Reference/Reference.html#//apple_ref/c/tdef/UILineBreakMode" rel="noreferrer noopener nofollow"><code>UILineBreakMode</code></a> 类型, 它的类型为 <a href="https://developer.apple.com/library/ios/documentation/Cocoa/Reference/ApplicationKit/Classes/NSParagraphStyle_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSLineBreakMode" rel="noreferrer noopener nofollow"><code>NSLineBreakMode</code></a>对于 iOS 6+,检查当前运行的 iOS 版本以确定要使用的类型的最佳(或更正确)方法应该是什么?直接做<code>[ systemVersion]</code>之类的东西是正确的,还是有更好的办法?</p>
<p>谢谢!</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>运行时不需要检查iOS版本,枚举值是一样的,从<code>UILineBreakMode</code>移动到<code>NSLineBreakMode</code>时编译后的代码不会改变/p>
<pre><code>enum {
NSLineBreakByWordWrapping = 0,
NSLineBreakByCharWrapping,
NSLineBreakByClipping,
NSLineBreakByTruncatingHead,
NSLineBreakByTruncatingTail,
NSLineBreakByTruncatingMiddle
};
typedef NSUInteger NSLineBreakMode
typedef enum {
UILineBreakModeWordWrap = 0,
UILineBreakModeCharacterWrap,
UILineBreakModeClip,
UILineBreakModeHeadTruncation,
UILineBreakModeTailTruncation,
UILineBreakModeMiddleTruncation,
} UILineBreakMode;
</code></pre></p>
<p style="font-size: 20px;">关于ios - NSLineBreakMode 枚举和向后兼容性,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/19652424/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/19652424/
</a>
</p>
页:
[1]