এখানে একটি কার্যকর সুইফট এক্সটেনশান:
সুইফ্ট ভি 5 এর জন্য আপডেট করুন:
extension UIScreen {
public var isRetina: Bool {
guard let scale = screenScale else {
return false
}
return scale >= 2.0
}
public var isRetinaHD: Bool {
guard let scale = screenScale else {
return false
}
return scale >= 3.0
}
private var screenScale: CGFloat? {
guard UIScreen.main.responds(to: #selector(getter: scale)) else {
return nil
}
return UIScreen.main.scale
}
}
ব্যবহার:
if UIScreen.main.isRetina {
// Your code
}
মূল:
extension UIScreen {
public func isRetina() -> Bool {
return screenScale() >= 2.0
}
public func isRetinaHD() -> Bool {
return screenScale() >= 3.0
}
private func screenScale() -> CGFloat? {
if UIScreen.mainScreen().respondsToSelector(Selector("scale")) {
return UIScreen.mainScreen().scale
}
return nil
}
}
ব্যবহার:
if UIScreen.mainScreen().isRetina() {
// your code
}