0

I currently have a UIView in Swift that has a background colour of red and a black outline with a UILabel inside.

Here is what my code looks like:

import UIKit

@IBDesignable
class AdventDoor: UIView
{
    @IBInspectable var shapeColor:UIColor = UIColor.blackColor()
    var width:CGFloat?



    required init(coder aDecoder: NSCoder) {
        //Initilse UIView
        super.init(coder: aDecoder)!
        //Create UILabel
        let dateLabel:UILabel = UILabel(frame: CGRect(x: (bounds.width-25)-5, y: 3, width: 25, height: 20))
        dateLabel.textAlignment = NSTextAlignment.Right
        dateLabel.text = self.restorationIdentifier!
        //Show the UILabel
        self.addSubview(dateLabel)

    }


    override func drawRect(rect: CGRect) {

        let drect = CGRect(x:0, y:0, width: bounds.width, height: bounds.height)
        let bpath:UIBezierPath = UIBezierPath(rect: drect)

        shapeColor.setFill()
        bpath.lineWidth = 5
        bpath.fill()
        bpath.stroke()
    }
}

Note: UIView may not show the design on the StoryBoard. To see the @IBDesignable you need to comment out the init function.

How would I animate the fill colour of the UILabel to close like sliding doors? I do not want the outline (stroke) to change width but I do want the inside to move?





This is what I want to happen:



Currently my UIView looks like this

enter image description here

What I want it to look like in the end is this

enter image description here

And in the middle of the animation I would like it to look like this

enter image description here

How would I achieve such animation using Core Graphics (or any other Library if needed)

iProgram
  • 6,057
  • 9
  • 39
  • 80
  • http://stackoverflow.com/questions/15651717/how-to-animate-cashapelayer-path-and-fillcolor – Shubhank Nov 24 '15 at 16:51
  • @Shubhank Could you make a post explaining it a bit more please? Also that is in Objective-C and not Swift 2. – iProgram Nov 24 '15 at 16:53
  • 1
    yup, i wont be able to port it to swift without writing code in IDE and testing it. I gave it you as a pointer for further help. If you are proficient in both you might be able to port it, or maybe come and hang around in the chat and i can guide better. Cant really give full time to post a proper solution sorry as i have some other work. – Shubhank Nov 24 '15 at 16:55
  • @Shubhank Thanks. How do I start a chat with you so you can give me a better guid? I would also try to port it, but I don't understand the Objective-C code so that won't work! – iProgram Nov 24 '15 at 16:59
  • http://chat.stackoverflow.com – Shubhank Nov 24 '15 at 17:00
  • @Shubhank Here is the link: http://chat.stackoverflow.com/rooms/96056/uiview-animation – iProgram Nov 24 '15 at 17:03

0 Answers0