zixun / GodEye

Automaticly display Log,Crash,Network,ANR,Leak,CPU,RAM,FPS,NetFlow,Folder and etc with one line of code based on Swift. Just like God opened his eyes
MIT License
3.85k stars 351 forks source link

Overriding default location of GodEye button #17

Closed headcrash13 closed 7 years ago

headcrash13 commented 7 years ago

I've got a quick patch to be able to specify (override) the default location of the GodEye button:

GodEye/Classes/Configuration/Configuration.swift

Add:

open class Configuration: NSObject {
    open private(set) var command = CommandConfiguration()
    /// default switch configuration
    open private(set) var defaultSwitch = SwitchConfiguration()
    open var location:CGPoint? // Override default location of the GodEye button
}

GodEye/Classes/UIWindow+GodEye.swift

extension UIWindow {

    func makeEye(with configuration:Configuration) {
        GodEyeController.shared.configuration = configuration
                .
                .
                .

Replace:

        let rect = CGRect(x: self.frame.size.width - 48, y: self.frame.size.height - 160, width: 48, height: 48)

With:

        var rect = CGRect(x: self.frame.size.width - 48, y: self.frame.size.height - 160, width: 48, height: 48)

        if let location = configuration.location {
            rect.origin = location
        }

Usage:

       let configuration = Configuration()
        configuration.location = CGPoint(x: 40.0, y: 40.0)
        GodEye.makeEye(with: self.window!, configuration: configuration)

There are cleaner ways of doing this, of course (e.g. put defaults in header, then just overwrite the x: and y: values), but I wanted to be the least intrusive as possible. :)

zixun commented 7 years ago

Good job! GodEye button should be specify~