菜单选项卡出现问题。我正在使用 carbonKit 框架

Having an issue in Menu Tabs. And I am using carbonKit Framework

我希望两个选项卡 (Hello World, Tab) 的宽度与控制器宽度相等。我把我的标签的完整代码。如果有人对此有建议。请给 suggestion.i 等待。快速评论和回答。

import UIKit
import CarbonKit

class ViewController: UIViewController, CarbonTabSwipeNavigationDelegate {

func generateImage(for view: UIView) -> UIImage? {
    defer {
        UIGraphicsEndImageContext()
    }
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, UIScreen.main.scale)
    if let context = UIGraphicsGetCurrentContext() {
        view.layer.render(in: context)
        return UIGraphicsGetImageFromCurrentImageContext()
    }
    return nil
}

var iconWithTextImage: UIImage {
    let button = UIButton()
    let icon = UIImage(named: "home")
    button.setImage(icon, for: .normal)
    button.setTitle("Home", for: .normal)
    button.setTitleColor(UIColor.blue, for: .normal)
    button.titleLabel?.font = UIFont.systemFont(ofSize: 15)
    button.contentEdgeInsets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 10)
    button.imageEdgeInsets = UIEdgeInsets(top: 0, left: -10, bottom: 0, right: 10)
    button.sizeToFit()
    return generateImage(for: button) ?? UIImage()
}

override func viewDidLoad() {
    super.viewDidLoad()

    let tabSwipe = CarbonTabSwipeNavigation(items: ["HELLO WORLD", "Tab"], delegate: self)
    tabSwipe.setTabExtraWidth(40)
    tabSwipe.insert(intoRootViewController: self)

}

func carbonTabSwipeNavigation(_ carbonTabSwipeNavigation: CarbonTabSwipeNavigation, viewControllerAt index: UInt) -> UIViewController {
    guard let storyboard = storyboard else { return UIViewController() }
    if index == 0 {
        return storyboard.instantiateViewController(withIdentifier: "FirstViewController")
    }
    return storyboard.instantiateViewController(withIdentifier: "SecondTableViewController")
}

}

这对你有帮助。

首先像这样设置 carbonSegmentControl frame 屏幕等于 Width

var frameRect: CGRect = (carbonTabSwipeNavigation.carbonSegmentedControl?.frame)!
frameRect.size.width = UIScreen.main.bounds.size.width
carbonTabSwipeNavigation.carbonSegmentedControl?.frame = frameRect

然后写下这条等宽的线。

carbonTabSwipeNavigation.carbonSegmentedControl?.apportionsSegmentWidthsByContent = false

1.等宽前

2。等宽后