相关疑难解决方法(0)

在Interface Builder中设置UIButton图层边框宽度和颜色

我可以使用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,所以我必须在代码中设置它.

objective-c interface-builder uibutton ios xcode6

17
推荐指数
3
解决办法
6万
查看次数

标签 统计

interface-builder ×1

ios ×1

objective-c ×1

uibutton ×1

xcode6 ×1