swift – 如何为iPhone6和6设备设置iphone4s,5和不同的字体和按钮大小?

swift – 如何为iPhone6和6设备设置iphone4s,5和不同的字体和按钮大小?,第1张

概述我正在开发一个iOS应用程序,我在iPhone 5,6,6中观察到UI所有字体都是不同的设备,但我的要求是iPhone4s的按钮大小和字体大小必须相同,5和iPhone 6和6的不同如何在我的应用程序中实现这一目标.我知道我们可以通过编程方式完成,但是有没有机会在故事板上使用自适应布局. 我使用的是xcode7.2,swift2. 提前致谢.. 我遇到了同样的问题并使用 Swifts Comput 我正在开发一个iOS应用程序,我在iPhone 5,6,6中观察到UI所有字体都是不同的设备,但我的要求是iPhone4s的按钮大小和字体大小必须相同,5和iPhone 6和6的不同如何在我的应用程序中实现这一目标.我知道我们可以通过编程方式完成,但是有没有机会在故事板上使用自适应布局.

我使用的是xcode7.2,swift2.

提前致谢..

解决方法 我遇到了同样的问题并使用 Swifts Computed Properties解决了它.
我创建了一个静态变量Fontsize,由于屏幕的大小,它可以使用适当的Fontsize进行动态初始化.

import UIKitclass 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            }        }    }}

然后使用它来设置按钮标签的Fontsize:

import UIKitclass 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...}
总结

以上是内存溢出为你收集整理的swift – 如何为iPhone6和6设备设置iphone4s,5和不同的字体和按钮大小?全部内容,希望文章能够帮你解决swift – 如何为iPhone6和6设备设置iphone4s,5和不同的字体和按钮大小?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1001611.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存