是否可以直接从界面构建器控制UIView边框属性(颜色,厚度等),或者我只能以编程方式进行操作?
我可以使用IB_DESIGNABLE和/或IBInspectable在Interface Builder中设置layer.borderWidth和layer.borderColor吗?我目前正在代码中创建我的按钮,但我希望能够在IB中设置所有这些,但我不确定这些属性是否可以在Xcode 6中设置.我想将它设置为IBOutlet而不是在代码中设置所有这些.这是我的按钮代码.
directions = [UIButton buttonWithType:UIButtonTypeRoundedRect];
directions.titleLabel.textAlignment = NSTextAlignmentCenter;
directions.titleLabel.font = [UIFont fontWithName:@"FranklinGothicStd-ExtraCond" size:20.0];
[directions setTitle:@"Directions" forState:UIControlStateNormal];
[directions setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
directions.frame = CGRectMake(20, 178, 70, 70);
directions.layer.borderWidth = 2.0f;
directions.layer.borderColor = [UIColor whiteColor].CGColor;
directions.clipsToBounds = YES;
directions.backgroundColor = [UIColor clearColor];
[directions addTarget:self action:@selector(getDirections:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:directions];
Run Code Online (Sandbox Code Playgroud)

我按照建议设置了这些值,并且模拟器中从不显示边框.编辑:我发现为什么在IB中设置这些值时边框没有显示出来.边框颜色是CGColor,所以我必须在代码中设置它.

对于那些不知道我在说什么的人,Xcode 6.0增加了新功能,IBDesignable和IBInspectable.
使用IBInspectable属性标记自定义视图时,这些属性将显示在IB中的"属性"检查器中.
同样,当您使用IBDesignable标记自定义UIView子类时,Xcode会编译您的视图并调用代码以在Xcode窗口中直接呈现视图对象,以便您可以看到它们的外观.
在自定义视图中添加IBDesignable和IBInspectable属性的技术在Swift和Objective-C中非常相似.IBInspectable属性显示在Interface Builder Attributes Inspector中,无论您使用哪种语言来定义它们.
我在Objective-C中创建了一个UIView类,并在Swift中创建了UIView的扩展,它将视图底层的borderWidth,cornerRadius,borderColor和layerBackgroundColor属性提升为视图的属性.如果更改属性,则扩展名/类别会根据需要键入转换,并将更改转发给图层.
IBInspectable部分运作良好.我看到并可以在IB属性检查器中设置新属性.
我可以在上周发誓,我的视图类别/扩展名上的IBDesignable属性也正常工作,我可以在IB中看到我的自定义UIView类别渲染,它具有更改的图层属性.本周它没有用.
我是产生幻觉的吗?
现有系统类的类别/扩展可以在使用IBDesignable设置时在Interface Builder中绘制自定义UI吗?
interface-builder ios xcode-storyboard ibdesignable ibinspectable
我有一个奇怪的问题.
我正在尝试在IB中设置用户定义的运行时属性.如下所示,我在viewController中设置了NSString statID属性,并希望在IB中为其提供测试值00000

当我编译时,我在构建时遇到此错误:"在10.6之前的Mac OS X版本上用户定义的运行时属性"
我知道我可以在iOS中从这里找到的iOS文档设置用户定义的属性到下面的部分:"为自定义对象配置运行时属性"
知道为什么它会给我错误吗?
我defined runtime attributes在按钮中使用。
layer.cornerRadius
layer.masksToBounds
layer.borderWidth
Run Code Online (Sandbox Code Playgroud)
我想把我的边框涂成绿色。但我的代码不起作用:
layer.borderUIColor
Run Code Online (Sandbox Code Playgroud)
边框为黑色。如何使用运行时属性绘制彩色边框?
ios ×4
border ×2
button ×1
ibdesignable ×1
iphone ×1
objective-c ×1
runtime ×1
uibutton ×1
uiview ×1
xcode6 ×1