随笔 - 400,  文章 - 0,  评论 - 7,  阅读 - 21万

 

 

复制代码
        //隐藏中间两条分割线
        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, width: 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
    }
复制代码

 

posted on   懂事长qingzZ  阅读(2241)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
历史上的今天:
2018-10-11 Aria2GUI 导出下载 刷新界面,任务消失

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示