ios UIPickerView自动尺寸

ukxgm1gy  于 11个月前  发布在  iOS
关注(0)|答案(1)|浏览(87)

对于UITableView中的动态行高,Swift

UITableViewAutomaticDimension

字符串
UIPickerView是否有等价物

hsvhsicv

hsvhsicv1#

您可以尝试获取pickerView行字符串的字符数,并将其复制一些像素数,以获得一个体面的行宽度,将动态适应您的内容。我必须在显示实时价格时这样做,并做了这样的事情:

func pickerView(_ pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat {
    let charcterWidth = 20
    let priceComponentWidth = CGFloat((self.lastPrice?.formatStringWithCommasOnly().count ?? 0) * charcterWidth)
    return priceComponentWidth
}

字符串

相关问题