How to set the font size and buttons the same for iphone4s, 5 and different for iPhone6 ​​and 6+ devices?

I’m working on an iOS application, and I watched the interface in iPhone 5,6,6+, all fonts are different devices on the device, but my requirement is that the button sizes and font sizes should be the same for iPhone4s, 5 and different for iPhone 6 and 6+. How can I do this in my application. I know that we can do this programmatically, but is there a chance to do this on a storyboard using responsive layouts.

I am using xcode7.2, swift2.

Thanks in advance.

+4
source share
1 answer

Swifts . fontsize, - .

import UIKit

class ViewFunctions {

    let screenSize = UIScreen.mainScreen().bounds.size
    static var fontsize: CGFloat {
        get {
            if screenSize.height >= 1024 { // iPad Pro
                return 16.0
            } else if screenSize.height >= 768 { // iPad
                return 16.0
            } else if screenSize.height >= 414 { // iPhone 6Plus
                return 15.0
            } else if screenSize.height >= 375 { // iPhone 6/s
                return 15.0
            } else if screenSize.height >= 320 { // iPhone 5/s
                return 14.0
            } else if screenSize.height >= 319 { // iPhone 4/s
                return 14.0
            } else {
                return 14.0
            }
        }
    }

}

, , -:

import UIKit

class TestClass {    

    var testButton: UIButton = UIButton(type: UIButtonType.System) as UIButton!
    testButton.titleLabel!.font = UIFont(name: "Helvetica Neue", size: ViewFunctions.fontsize)
    testButton.setTitle("Test", forState: .Normal)
    // add button to view or sth like that...

}
0

Source: https://habr.com/ru/post/1623751/


All Articles