"Swift 2.1" adds click events and click Effects for UIView

Source: Internet
Author: User

Objective

UIView not like UIButton added Click event will have a click effect, experience is much worse, here respectively through customization and extension to achieve similar UIButton effect.

Statement
Welcome reprint, but please keep the original source of the article:)
Blog Park: http://www.cnblogs.com
Farmer Uncle: Http://over140.cnblogs.com

Body

First, add a click event for UIView

extension UIView {    func addonclicklistener (Target:anyobject, action:selector) {        =  UITapGestureRecognizer (Target:target, action:action)        1        true         Addgesturerecognizer (GR)    }}

Second, add click Effect for UIView

classUivieweffect:uiview {OverrideFunc Touchesbegan (touches:set<uitouch>, witheventEvent: Uievent?) {BackgroundColor=uicolor.grouptableviewbackgroundcolor ()}OverrideFunc touchescancelled (touches:set<uitouch>?, WitheventEvent: Uievent?) {uiview.animatewithduration (0.15, animations: {(), VoidinchSelf.backgroundcolor=Uicolor.clearcolor ()}) }    OverrideFunc touchesended (touches:set<uitouch>, witheventEvent: Uievent?) {uiview.animatewithduration (0.15, animations: {(), VoidinchSelf.backgroundcolor=Uicolor.clearcolor ()}) }}

Here everyone can be replaced by their own click effect, if it is Uiimageview can be replaced by click Change Transparency.

"Swift 2.1" adds click events and click Effects for UIView

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.