我正在使用图片实现自定义选择器视图。问题是,图像彼此重叠,如下所示:
这是在选择器视图中配置图像的代码:
func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView!) -> UIView {
let chosenImage: UIImageView = UIImageView(image: UIImage(named: iconArray[row]))
NSLog("choosen image \(iconArray[row])")
let workaroundImageView: UIImageView = UIImageView(frame: chosenImage.frame)
workaroundImageView.backgroundColor = UIColor(patternImage: chosenImage.image!)
return workaroundImageView
}
我错过了什么?有什么建议?
答案 0 :(得分:1)
在UIPickerView的委托中使用rowHeightForComponent。
pickerView:rowHeightForComponent:
为组件提供所需的行高。
func pickerView(pickerView: UIPickerView!, rowHeightForComponent component: Int) -> CGFloat