ios 可以在 Storyboard 中设置 UITextView 或 UILabel 的边框吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16650697/
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-08-30 23:39:09  来源:igfitidea点击:

Can the border of UITextView or UILabel be set in Storyboard?

iphoneiosipadinterface-builderstoryboard

提问by Doug Null

I want to set the border of a UITextViewor a UILabelin a Storyboard. Can it be done?

我想在 Storyboard 中设置 aUITextView或 a的边框UILabel。可以做到吗?

Programmatically, it is setBorderColorand setBorderWidth.

以编程方式,它是setBorderColorsetBorderWidth

But can the border be set in a Storyboard?

但是可以在 Storyboard 中设置边框吗?

回答by Dan Morrow

As was previously pointed out, these properties are part of a layer, not part of a view. But you can still set their values in IB. As hypercrypt pointed out, you can use User Defined Runtime Attributes. Since all views have a "layer" property, you can set "layer.borderWidth" for instance.

如前所述,这些属性是图层的一部分,而不是视图的一部分。但是您仍然可以在 IB 中设置它们的值。正如 hypercrypt 所指出的,您可以使用用户定义的运行时属性。由于所有视图都有一个“layer”属性,例如您可以设置“layer.borderWidth”。

Here's a case, where I'm changing the cornerRadius. Works great.

这是一个案例,我正在更改cornerRadius。效果很好。

enter image description here

在此处输入图片说明

回答by NANNAV

use simple code in .m,it show border in view

在.m中使用简单的代码,它在视图中显示边框

view.layer.cornerRadius = 5.0f;
view.layer.masksToBounds = NO;
view.layer.borderWidth = .5f;
view.layer.shadowColor = [UIColor orangeColor].CGColor;
view.layer.shadowOpacity = 0.4;
view.layer.shadowRadius = 5.0f;

回答by hypercrypt

If you're targeting iOS 6+ you can use the User Defined Runtime Attributesin the Identity Inspectorto set any properties. Performance is not an issue for either, so it doesn't matter.

如果你的目标的iOS 6+您可以使用用户定义的属性运行身份检查设置任何属性。性能对两者都不是问题,因此无关紧要。