【发布时间】:2014-11-27 11:28:16
【问题描述】:
我可以使用 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];
我按照建议设置了这些值,并且边框从未在模拟器中显示。 编辑:我发现为什么在 IB 中设置这些值时没有显示边框。边框颜色是 CGColor,所以我必须在代码中设置它。
【问题讨论】:
标签: ios objective-c uibutton interface-builder xcode6