美文网首页iOS轮子
iOS视图封装 - DJButton

iOS视图封装 - DJButton

作者: SealShile | 来源:发表于2017-08-23 21:33 被阅读6次

    DJButton

    https://github.com/shileseal/DJButton
    欢迎star和fork

    一个自定义Button中imageView和titleLabel位置的自定义控件

    功能

    1. 快速创建4种布局的UIButton (1.左icon,右title 2.左title,右icon 3.上icon,下title 4.上title, 下icon)
    2. 轻松设定icon和title之间的距离
    3. 实时渲染到Attributes Inspector,用Storyboard创建时,所见即所得

    用法

            // 1.样式:左标题右图片
            let firstButton = DJButton(layoutStyle: .leftTitleImage)
            firstButton.setTitle("button", for: .normal)
            firstButton.setTitleColor(UIColor.red, for: .normal)
            firstButton.setImage(UIImage(named: "icon"), for: .normal)
            firstButton.frame = CGRect(x: 0, y: 0, width: 110, height: 110)
            // 图片和标题之间的间隔
            firstButton.gap = 20
            self.view.addSubview(firstButton)
            
            // 2.样式:上图片下标题
            let secondButton = DJButton(layoutStyle: .upImageTitle)
            secondButton.setTitle("button", for: .normal)
            secondButton.setTitleColor(UIColor.red, for: .normal)
            secondButton.setImage(UIImage(named: "icon"), for: .normal)
            secondButton.frame = CGRect(x: 0, y: 150, width: 110, height: 110)
            secondButton.gap = 10
            self.view.addSubview(secondButton)
            
            // 3.样式:上标题下图片
            let thirdButton = DJButton(layoutStyle: .upTitleImage)
            thirdButton.setTitle("button", for: .normal)
            thirdButton.setTitleColor(UIColor.red, for: .normal)
            thirdButton.setImage(UIImage(named: "icon"), for: .normal)
            thirdButton.frame = CGRect(x: 0, y: 300, width: 110, height: 110)
            thirdButton.gap = 20
            self.view.addSubview(thirdButton)
            
            // 4.样式:Storyboard创建,请参照Main.Storyboard
    

    相关文章

      网友评论

        本文标题:iOS视图封装 - DJButton

        本文链接:https://www.haomeiwen.com/subject/dgbjdxtx.html