azurechen / ACTabScrollView

A fancy Menu and Pager UI extends UIScrollView with elegant, smooth and synchronized scrolling tabs.
MIT License
115 stars 35 forks source link

Change Arrow Indicator #11

Open silviocolman opened 7 years ago

silviocolman commented 7 years ago

Could the arrow indicator be pointed in the direction above?

thihaaung6245 commented 7 years ago

First of all, I want to say this is amazing paging menu which run smoothly and goes everything well. Thanks to the developer who make this. It run perfectly on all view and orientation. I haven't tested in containerview yet. But, I can tell you this is good.

Plus, the arrow indicator upside or downside feature should be added don't you think? If you can i mean if you have free time, would you mind help us contribute. Thanks

+1

azurechen commented 7 years ago

Hi @silviocolman and @htarwara6245 Thanks for your suggestions! Recently I am busy in my works so I have no enough time to develop some new features. The arrow indicator direction is one of the important issues. And any contribution will be welcome!

If you really need this feature. I think it is quite easy to make the effect you want. Just find class ArrowView in /Sources/ACTabScrollView.swift and you can modify the following code to change the direction.

ctx?.move(to: CGPoint(x: 0, y: 0))
ctx?.addQuadCurve(to: CGPoint(x:maxX * 0.2 , y: maxY * 0.2), control: CGPoint(x: maxX * 0.12, y: 0))
ctx?.addLine(to: CGPoint(x: midX - maxX * 0.05, y: maxY * 0.9))
ctx?.addQuadCurve(to: CGPoint(x: midX + maxX * 0.05, y: maxY * 0.9), control: CGPoint(x: midX, y: maxY))
ctx?.addLine(to: CGPoint(x: maxX * 0.8, y: maxY * 0.2))
ctx?.addQuadCurve(to: CGPoint(x: maxX, y: 0), control: CGPoint(x: maxX * 0.88, y: 0))

Thank you very much

thihaaung6245 commented 7 years ago

@azurechen No that doesn't work as expected, means arrow is disappear. I solved it like that. I will try to contribute as well. But, currently my code just raw code. I might need some help from you. If you have free time, help me solve those as well.

class ArrowView : UIView {

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.clear
    }

    var rect: CGRect!
    var arrorBackgroundColor: UIColor?

    var midX: CGFloat { return rect.midX }
    var midY: CGFloat { return rect.midY }
    var maxX: CGFloat { return rect.maxX }
    var maxY: CGFloat { return rect.maxY }

    override func draw(_ rect: CGRect) {
        self.rect = rect

        guard let ctx = UIGraphicsGetCurrentContext() else { return }

        // Sample to really fill the background before drawing the arrow.
        //ctx.setFillColor(UIColor.yellow.cgColor)
        //ctx.fill(bounds)

        ctx.beginPath()
        ctx.move(to: CGPoint(x: 0, y: bounds.maxY))
        ctx.addLine(to: CGPoint(x: bounds.midX, y: bounds.minY))
        ctx.addLine(to: CGPoint(x: bounds.maxX, y: bounds.maxY))
        ctx.addLine(to: CGPoint(x: 0, y: bounds.maxY))
        ctx.closePath()

        ctx.setFillColor((arrorBackgroundColor?.cgColor)!)
        ctx.fillPath()
    }

}

This was only drawing arrow view to upside. But, we need to edit arrow view frame too. There are two position that change arrow view in the source, just find "arrowView.frame.origin" and replace it with this

arrowView.frame.origin = CGPoint(x: (self.bounds.width - arrowView.bounds.width) / 2, y: tabSectionHeight - arrowView.bounds.height)

And change arrow background color as you wanted at there :

arrowView.arrorBackgroundColor = self.contentSectionBackgroundColor

Now you will have like this :

actabscrollview

Happy Coding!!!

azurechen commented 7 years ago

@htarwara6245 Yes, you are right! Just changing the direction is not enough. I very appreciate your contribution! I will update the code as soon as possible. Before that @silviocolman can try to use @htarwara6245's solution. It's cool.

silviocolman commented 7 years ago

@htarwara6245 @htarwara6245 Many thanks for this week this week testing the code in my app

thihaaung6245 commented 7 years ago

If that worked out, you can close the issue.

thihaaung6245 commented 7 years ago

@silviocolman, that was not part of this question. It's belong to the UITableView Delegates and Datasource which mean you have to learn these basic first before you start using UITableView.

thihaaung6245 commented 7 years ago

@azurechen , I created pull request. Can you please take a look when you have time?

azurechen commented 7 years ago

Hi @htarwara6245 Thank for your pull request. I have reviewed your code and give you some comments. And please reset the following files. These files shouldn't be changed in this commit.

.DS_Store
ACTabScrollView.xcodeproj/project.pbxproj
ACTabScrollView/Base.lproj/Main.storyboard
ACTabScrollView/Info.plist

Thank you very much