【问题标题】:UIPickerView Margin LeftUIPickerView 左边距
【发布时间】:2022-01-18 13:44:29
【问题描述】:

对于带有标题的 UIPickerView,我正在寻找一种方法来为标题提供左边距。目前,前两个词似乎被裁剪了。

我正在使用这个 UIPickerView 方法来分配标题。

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
    let pickerLabel = UILabel()
    let title = NSAttributedString(string: castProductDetails[row].price, attributes:[.font: FontFamily.Roboto.medium.font(size: 16.0), .foregroundColor: Asset.Colors.primaryText.color] )
    pickerLabel.attributedText = title
    return pickerLabel
}

Adding screenshot for reference.

【问题讨论】:

    标签: swift uipickerview


    【解决方案1】:

    这对我有用。

    func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
        
        let margin : CGFloat = 20.0
        
        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.firstLineHeadIndent = margin
        paragraphStyle.headIndent = margin
        
        let title = NSMutableAttributedString(string: yourArrayHere[row])
        title.addAttribute(.paragraphStyle,
                           value: paragraphStyle,
                           range: NSRange(location: 0, length: title.length))
        
        let pickerLabel = UILabel()
        pickerLabel.attributedText = title
        return pickerLabel
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-01
      • 2016-12-07
      • 1970-01-01
      • 1970-01-01
      • 2015-03-10
      • 2016-09-29
      • 1970-01-01
      相关资源
      最近更新 更多