| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- //
- // MODashedLineView.m
- // MiMoLive
- //
- // Created by SuperC on 2025/3/3.
- //
- #import "MODashedLineView.h"
- @implementation MODashedLineView
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- [self commonInit];
- }
- return self;
- }
- - (void)awakeFromNib {
- [super awakeFromNib];
- [self commonInit];
- }
- - (void)prepareForInterfaceBuilder {
- [super prepareForInterfaceBuilder];
- [self setNeedsDisplay];
- }
- - (void)commonInit {
- self.backgroundColor = [UIColor clearColor];
- self.dashColor = self.dashColor ?: [UIColor blackColor];
- self.dashLength = self.dashLength ?: 5;
- self.dashSpacing = self.dashSpacing ?: 5;
- self.lineWidth = self.lineWidth ?: 2;
- }
- - (void)drawRect:(CGRect)rect {
- CGContextRef context = UIGraphicsGetCurrentContext();
- CGContextSetStrokeColorWithColor(context, self.dashColor.CGColor);
- CGContextSetLineWidth(context, self.lineWidth);
- CGFloat dashPattern[] = {self.dashLength, self.dashSpacing};
- CGContextSetLineDash(context, 0, dashPattern, 2);
- CGContextMoveToPoint(context, 0, rect.size.height / 2);
- CGContextAddLineToPoint(context, rect.size.width, rect.size.height / 2);
-
- CGContextStrokePath(context);
- }
- @end
|