Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用自定义导航栏,修改导航栏宽度后,标题会跳动 #211

Open
ZAREMYDREAM opened this issue Aug 1, 2022 · 1 comment

Comments

@ZAREMYDREAM
Copy link

使用自定义导航栏,修改导航栏宽度后,标题会跳动。使用以下代码自定义UINavigationBar,在demo中Main将导航栏修改成该类,可复现

class JGJNavigationBar: UINavigationBar {
    @objc var margins: CGFloat = 16
    override func layoutSubviews() {
        super.layoutSubviews()

        if #available(iOS 13.0, *) {
            for view in subviews {
                if "\(view.self)".contains("UINavigationBarContentView") {
                    let margins = view.layoutMargins
                    self.margins = margins.left
                    view.frame = CGRect(x: -margins.left, y: view.bounds.origin.y, width: view.bounds.size.width  + margins.left + margins.right, height: view.bounds.size.height)

                    break
                }


            }
        } else {
            for view in subviews {
                if "\(view.self)".contains("ContentView") {
                    view.layoutMargins = UIEdgeInsets(top: view.layoutMargins.top, left: 0, bottom: view.layoutMargins.bottom, right: 0)
                    self.margins = view.layoutMargins.left
                    break
                }
            }
        }
    }
}
@ZAREMYDREAM
Copy link
Author

JXCategoryView不存在该问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant