[英]Draw line in UIButton that already has png image in it
如果你想在xib上绘制它,你必须自定义你的按钮。
@interface DrawLineButton()
@property (nonatomic, strong) IBInspectable UIColor* fillColor;
@property (nonatomic, assign) IBInspectable CGFloat toLeft;
@property (nonatomic, assign) IBInspectable CGFloat toRight;
@property (nonatomic, assign) IBInspectable CGFloat toBottom;
@property (nonatomic, assign) IBInspectable CGFloat lineHeight;
@end
@implementation DrawLineButton
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
CGRect pathRect = CGRectMake(_toLeft,
self.bounds.size.height - _toBottom - _lineHeight,
self.bounds.size.width - _toLeft - _toRight,
_lineHeight);
UIBezierPath* path = [UIBezierPath bezierPathWithRect:pathRect];
path.lineWidth = _lineHeight;
UIColor* fillColor = _fillColor;
[fillColor set];
[path fill];
[path stroke];
}
@end
//.h
IB_DESIGNABLE //Must this
@interface DrawLineButton : UIButton
@end
我希望能帮助你,谢谢!
一个简单的解决方案,如果您不确定如何绘制线条,通常是创建一个UILabel,将框架设置为:
UILabel *line = [[UILabel alloc] initWithFrame(x,y,w,h)];
然后,设置标签的背景颜色
line.backgroundColor = [UIColor red];
然后,将其添加到按钮
[button addSubview:line];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.