xcode 如何为 UIPickerView 添加边框?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28919450/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:46:56  来源:igfitidea点击:

How to add a border to a UIPickerView?

iosxcodeuser-interfaceuipickerview

提问by Matt Porter

How would you add a border to a UIPickerView? Cant seem to find any property for it. Is there some kind of work around?

你将如何为 UIPickerView 添加边框?似乎无法为它找到任何属性。有什么解决办法吗?

I actually have two UIPickerViews next to each other, if possible I would like to get a thin white border around the both of them!

我实际上有两个彼此相邻的 UIPickerViews,如果可能的话,我想在它们周围都有一个细的白色边框!

回答by Lyndsey Scott

As with any view, you can add a border by manipulating your UIPickerView's layer property, ex:

与任何视图一样,您可以通过操作您UIPickerView的图层属性来添加边框,例如:

// In Swift 3
picker.layer.borderColor = UIColor.white.cgColor
picker.layer.borderWidth = 1

// In Swift
picker.layer.borderColor = UIColor.whiteColor().CGColor
picker.layer.borderWidth = 1

// In Obj-C
picker.layer.borderColor = [UIColor whiteColor].CGColor;
picker.layer.borderWidth = 1;

回答by Naveed Khan

You can also use the delegate method to apply styles and css on DatePicker .. For example

您还可以使用委托方法在 DatePicker 上应用样式和 css .. 例如

func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView?) -> UIView {


picker.layer.borderColor = UIColor.whiteColor().CGColor
picker.layer.borderWidth = 1

return view 


}

This method will aplly all the properties on datepicker that is used in that particular view controller .

此方法将应用在该特定视图控制器中使用的 datepicker 上的所有属性。