Created
August 9, 2015 01:35
-
-
Save motokiee/28a75c0a2a7a548807b6 to your computer and use it in GitHub Desktop.
dash line custom view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
IB_DESIGNABLE | |
@interface CustomView : UIView | |
@property (nonatomic) IBInspectable CGFloat lineWidth; | |
@property (nonatomic) IBInspectable CGFloat dotWidth; | |
@property (nonatomic) IBInspectable CGFloat dotInterval; | |
@property (nonatomic) IBInspectable UIColor *lineColor; | |
@property (nonatomic) IBInspectable BOOL *isThinLine; | |
@end | |
@implementation CustomView | |
- (void)drawRect:(CGRect)rect { | |
CGFloat point = self.lineWidth; | |
if (self.lineWidth == 1 && self.isThinLine) { | |
point = self.lineWidth / [UIScreen mainScreen].scale; | |
} | |
CGRect myRect = CGRectMake(point, point, rect.size.width - point * 2, rect.size.height - point * 2); | |
UIBezierPath *arc = [UIBezierPath bezierPathWithRoundedRect:myRect cornerRadius:10.0f]; | |
[self.lineColor setStroke]; | |
arc.lineWidth = self.lineWidth; | |
CGFloat dash[] = {point, self.dotInterval}; | |
[arc setLineDash:dash count:2 phase:0]; | |
[arc stroke]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment