iOS Tips---Swift to determine iOS version and adaptation

Source: Internet
Author: User



operatingSystemVersion

为了更复杂的版本比较,operatingSystemVersion能够被直接检查。将它和Swift模式比较和switch语句组合,可以使得代码更简洁。


let os = NSProcessInfo().operatingSystemVersion

switch (os.majorVersion, os.minorVersion, os.patchVersion) { case (8, _, _):      println( "iOS >= 8.0.0" ) case (7, 0, _):      println( "iOS >= 7.0.0, < 7.1.0" ) case (7, _, _):      println( "iOS >= 7.1.0, < 8.0.0" ) default :      println( "iOS < 7.0.0" )

}





Uidevice systemversion

Unfortunately, the new Nsprocessinfo API is not particularly useful at this time because they do not take effect on iOS 7.

As an alternative, you can use the Systemversion property uidevice to check:

switch UIDevice.currentDevice().systemVersion.compare( "8.0.0" , options: NSStringCompareOptions.NumericSearch) { case .OrderedSame, .OrderedDescending:      println( "iOS >= 8.0" ) case .OrderedAscending:      println( "iOS < 8.0" ) }



Adaptation screen

switch uidevice. Currentdevice (). systemversion . Compare ("7.0.0", Options: nsstringcompareoptions. Numericsearch) {

case . Orderedsame,. Ordereddescending:

println("IOS >= 7.0")

self. Edgesforextendedlayout = Uirectedge . None

self. automaticallyadjustsscrollviewinsets = false

case . Orderedascending:

println("IOS < 7.0")

}


iOS Tips---Swift to determine iOS version and adaptation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.