UIView+Border(添加任意一边)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/WSxiaotao/article/details/37760717

左边

   

 CALayer *bottomBorder = [CALayer layer];

    bottomBorder.frame = CGRectMake(0.0f, 0.0f, 1.0f, btnValite.frame.size.height);

    bottomBorder.backgroundColor = [UIColor colorWithWhite:0.8f
                                                     alpha:1.0f].CGColor;

    [button.layer addSublayer:bottomBorder];

UIButton+Border.h

@interface UIButton (Border)
-(void)addBottomBorderWithColor: (UIColor *) color andWidth:(CGFloat) borderWidth;
-(void)addLeftBorderWithColor: (UIColor *) color andWidth:(CGFloat) borderWidth;
-(void)addRightBorderWithColor: (UIColor *) color andWidth:(CGFloat) borderWidth;
-(void)addTopBorderWithColor: (UIColor *) color andWidth:(CGFloat) borderWidth;
@end

这边网上的方法加个类别 很方便

UIButton+Border.m

@implementation UIButton (Border)
-(void)addTopBorderWithColor:(UIColor )color andWidth:(CGFloat) borderWidth { CALayerborder = [CALayer layer]; border.backgroundColor = color.CGColor;
border.frame = CGRectMake(0, 0, self.frame.size.width, borderWidth); [self.layer addSublayer:border]; }
-(void)addBottomBorderWithColor:(UIColor )color andWidth:(CGFloat) borderWidth { CALayerborder = [CALayer layer]; border.backgroundColor = color.CGColor;
border.frame = CGRectMake(0, self.frame.size.height - borderWidth, self.frame.size.width, borderWidth); [self.layer addSublayer:border]; }
-(void)addLeftBorderWithColor:(UIColor )color andWidth:(CGFloat) borderWidth { CALayerborder = [CALayer layer]; border.backgroundColor = color.CGColor;
border.frame = CGRectMake(0, 0, borderWidth, self.frame.size.height); [self.layer addSublayer:border]; }
-(void)addRightBorderWithColor:(UIColor )color andWidth:(CGFloat) borderWidth { CALayerborder = [CALayer layer]; border.backgroundColor = color.CGColor;
border.frame = CGRectMake(self.frame.size.width - borderWidth, 0, borderWidth, self.frame.size.height); [self.layer addSublayer:border]; }
@end



阅读更多
换一批

没有更多推荐了,返回首页