swift 自定义购物车计数器

<span style="font-family: SimSun; background-color: rgb(255, 255, 255);">看着公司项目中拥有这个自定义控件,想想后面肯定也要替换成swift的,所以,就开始动手干了起来.</span>

购物车计数器,目前设计了两种类型,一种就是线框圆角,一种就是按钮圆形.

目前支持加/减,以及设置每一步增加或减少的数值,支持闭包回调.当然同时也涉及了简单的VFL(Visual Format Language)的使用.

就目前来说,离笔者想要的功能也大致一样了,如果有新的功能,大家可以修改修改.

效果图是这样的,就没有制作动图了,将就吧:


那先上代码了:

//
//  NBCountView.swift
//  NBCountView
//
//  Created by NapoleonBai on 15/9/20.
//  Copyright © 2015年 NapoleonBai. All rights reserved.
//

import UIKit

enum NBCountViewShowType{
    /// 圆角按钮
    case FilletButton
    /// 圆形按钮
    case CircleButton
}

struct NBCountConfig {
    /// 设置私有属性显示样式
    private var mCountViewType : NBCountViewShowType = .FilletButton
    var countViewShowType : NBCountViewShowType{
        get{
            return mCountViewType
        }
        set(newShowType){
            self.mCountViewType = newShowType
        }
    }
    
    /// 设置私有属性TintColor
    private var mTintColor : UIColor = UIColor.greenColor()
    var tintColor : UIColor {
        get{
            return mTintColor
        }
        set(newTintColor){
            self.mTintColor = newTintColor
        }
    }
    init(){}
    /**
    增加带参数的构造方法
    
    - parameter countViewShowType: 显示样式
    - parameter borderColor:       borderColor
    
    - returns: 当前结构体实例
    */
    init(countViewShowType:NBCountViewShowType,tintColor:UIColor){
        self.countViewShowType = countViewShowType
        self.tintColor = tintColor
    }
}

class NBCountView : UIView ,UITextFieldDelegate{

    
    /// 设置默认的两个按钮以及输入框
    private var lessBtn : UIButton = UIButton.init(type:.Custom)
    private var addBtn : UIButton = UIButton.init(type:.Custom)
    private var countTextField : UITextField = UITextField.init()
    
    private var mViewConfig : NBCountConfig = NBCountConfig()
    /// 修改之前的值
    private var updateAgainValue = 0
    /// 当前显示值,缺省为0
    private var mCurrentValue : Int = 0
    /// 当前显示值,动态设置
    var currentVal
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值