美文网首页其他知识
iOS xib中 button 边框设置 附(如何给类别添加

iOS xib中 button 边框设置 附(如何给类别添加

作者: milk_powder | 来源:发表于2016-03-29 16:25 被阅读3918次

选中xib中的button,在右边栏的第三个标签页中第三项是User Defined Runtime Attributes

添加一个keyPath,keyPath值为layer.borderWidth,类型为NSNumber,值为你想要设置的边框宽度。如图:

第二个是设置边框的颜色,上面设置颜色无效 这时候需要给CALayer增加一个分类

然后 代码如下

////  CALayer+XibConfiguration.h Copyright

//#import@interface CALayer (XibConfiguration)

// This assigns a CGColor to borderColor.

@property(nonatomic, assign) UIColor *borderUIColor;

@end

//

//  CALayer+XibConfiguration.m

//

//

//   All rights reserved.

//

#import "CALayer+XibConfiguration.h"

@implementation CALayer (XibConfiguration)

-(void)setBorderUIColor:(UIColor*)color

{

self.borderColor = color.CGColor;

}

-(UIColor*)borderUIColor

{

return [UIColor colorWithCGColor:self.borderColor];

}

@end

相关文章

网友评论

  • 菜鸟吃咸鱼:我检讨,可以,我错了,我只设置了1步骤,而步骤也要设置,引入就可以,真的可以,谢谢。
    milk_powder:@机智的大锤 嗯嗯
  • 菜鸟吃咸鱼:不管用啊。。。

本文标题:iOS xib中 button 边框设置 附(如何给类别添加

本文链接:https://www.haomeiwen.com/subject/glsslttx.html