Skip to content

vikingosegundo/ShapedButtons

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is an example code for a stackoverflow question

While a storyboard file looks like

storyboard

the app will show the buttons as

triangle

The shape of the button is set by proving a path which will mask the button.

var shape: UIBezierPath = UIBezierPath() {
    didSet{
        let l = CAShapeLayer()
        l.path = shape.cgPath
        self.layer.mask = l
    }
}

The hit testing is done by determining if an event was triggered at a point that lays in the given shape path, there-for a touch will only be recognize at the visible parts of the button.

override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
    return  shape.cgPath.contains(point)
}

A more complex form using four triangles and a circle, all buttons:

compassrose

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages