zoukankan      html  css  js  c++  java
  • swift UIPickerView 更改背景色,隐藏分割线,修改字体的font和颜色

            //隐藏中间两条分割线
            if pickerV.subviews.count >= 3{
                pickerV.subviews[1].isHidden = true
                pickerV.subviews[2].isHidden = true
            }
            
            //修改选中行的背景色
            for subView in pickerV.subviews {
                if subView.subviews.count != 0 {
                    let contentViews = subView.subviews[0]
                    for rowView in contentViews.subviews {
                        if rowView.center.y == contentViews.center.y {
                            //背景view
                            rowView.backgroundColor = UIColor.init(hexString: "#F5F5F5")
                            break
                        }
                    }
                    break
                }
            }
     // 推荐 显示需要 label 。文字大小, 颜色等
        func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
            
            //显示的文字
            var showStr = ""
            switch component {
            case 0:
                showStr = "(self.dataArr[component][row].selectTextStr)年"
            case 1:
                showStr = "(self.dataArr[component][row].selectTextStr)月"
            case 2:
                showStr = "(self.dataArr[component][row].selectTextStr)日"
            default:break
            }
            //修改字体大小, 颜色
            let arrStr = NSAttributedString.highLightText(showStr, highLightString: "", normalFont: UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.regular), highLightFont: nil, normalColor: UIColor.init(hexString: "#333333"), highLightColor: nil)
            
            //这里宽度随便给的, 高度也是随便给的 不能比row的高度大,能显示出来就行
            let showLabel = UILabel(frame: CGRect(x: 0, y: 0,  100, height: 34))
            showLabel.textAlignment = .center
            //重新加载label的文字内容
            showLabel.attributedText = arrStr
            return showLabel
        }
        
        //    //改变字体颜色,目前字体大小更改不了,不推荐
        //    func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
        //
        //
        //        var str = ""
        //        switch component {
        //        case 0:
        //            str = "(self.dataArr[component][row].selectTextStr)年"
        //        case 1:
        //            str = "(self.dataArr[component][row].selectTextStr)月"
        //        case 2:
        //            str = "(self.dataArr[component][row].selectTextStr)日"
        //        default:break
        //        }
        //        return NSAttributedString.highLightText(str, highLightString: "", normalFont: UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.regular), highLightFont: nil, normalColor: UIColor.init(hexString: "#333333"), highLightColor: nil)
        //    }
        
        //每行的高度
        func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
            return 34
        }
  • 相关阅读:
    最短路径(Dijkstra算法)
    图的优先级搜索
    图的遍历(搜索)

    树(二叉树)
    TF-池化函数 tf.nn.max_pool 的介绍
    TF-卷积函数 tf.nn.conv2d 介绍
    TF-图像的深度和通道的概念(转)
    MongoDB-MongoDB重装系统后恢复
    MYSQL-重做系统恢复MYSQL过程
  • 原文地址:https://www.cnblogs.com/qingzZ/p/11655963.html
Copyright © 2011-2022 走看看