swift - 如何在标签栏上方底部的所有 View Controller 中添加一个公共(public) View

标签 swift xcode swift2

<分区>

我需要添加一个具有一些按钮并出现在所有 View Controller 中的 View 。该 View 应包含一个水平 ScrollView ,其中放置了所有按钮。

View 需要位于标签栏的顶部。类似于图片中的 The player in the apple music application, on top of the tab bar in the bottom

感谢任何帮助。谢谢!

最佳答案

试试这个:

这是 Swift 3 代码。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

    view.frame = CGRect(x: 0, y: UIScreen.main.bounds.height-100, width: UIScreen.main.bounds.width , height: 100)
    //window?.willRemoveSubview(view)

    //Add ScrollView to View
    let scrollview = UIScrollView(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height))
    scrollview.contentSize = CGSize( width: view.frame.size.width*2, height: view.frame.size.height)
    scrollview.backgroundColor = UIColor.blue
    scrollview.removeFromSuperview()
    view.addSubview(scrollview)

    //Add Button to Scrollview
    let btn = UIButton(frame: CGRect(x: scrollview.frame.size.width/3, y: scrollview.frame.size.height/2, width: 50, height: 30))
    btn.setTitle("Heloo", for: UIControlState.normal)
    btn.setTitleColor(UIColor.red, for: UIControlState.normal)
    let btn2 = UIButton(frame: CGRect(x: scrollview.frame.size.width/2, y: scrollview.frame.size.height/2, width: 50, height: 30))
    btn2.setTitle("Hiiii", for: UIControlState.normal)
    btn2.setTitleColor(UIColor.red, for: UIControlState.normal)
    scrollview.addSubview(btn)
    scrollview.addSubview(btn2)

    window?.makeKeyAndVisible()
    window?.insertSubview(view, at: 0)
    window?.bringSubview(toFront: view)

    return true
}

希望对你有帮助

关于swift - 如何在标签栏上方底部的所有 View Controller 中添加一个公共(public) View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39542288/

相关文章:

ios - Swift - 带有 Objective-C 选择器 '*()' 的方法 '*' 与具有相同 Objective-C 选择器的父类(super class) '*' 的 'UIView' 的 getter 冲突

ios - 以编程方式调整 UIImage 大小不起作用

swift - 如何从内存中清除 SKSpriteNode?

swift - 检查Swift中的枚举是否属于常量集

ios - 具有可选择日期范围的日历

ios - 安装 CocoaPods Podfile 后 Xcode 调试器不显示变量信息

ios - 使用 TWTweetComposeViewController 的部署目标与基础 SDK

iphone - 静态 UILabel 未显示在 uiview 中

macos - 使用 Swift 2 在 OSX 上设置桌面背景

ios - Xcode7与array.filter方法的误解