Created
January 7, 2016 10:32
-
-
Save bigeyex/a7e86ab88236b7b5a830 to your computer and use it in GitHub Desktop.
"Extended UI Kit"
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 MBFlipImageView : UIImageView | |
@property (nonatomic) IBInspectable UIImage *onImage; | |
@property (nonatomic) IBInspectable UIImage *offImage; | |
- (void)flipOn; | |
- (void)flipOff; | |
- (void)setFlip:(bool)value; | |
@end |
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 "MBFlipImageView.h" | |
@implementation MBFlipImageView | |
/* | |
// Only override drawRect: if you perform custom drawing. | |
// An empty implementation adversely affects performance during animation. | |
- (void)drawRect:(CGRect)rect { | |
// Drawing code | |
} | |
*/ | |
- (void)flipOn{ | |
self.image = self.onImage; | |
} | |
- (void)flipOff{ | |
self.image = self.offImage; | |
} | |
- (void)setFlip:(bool)value{ | |
if(value){ | |
[self flipOn]; | |
} | |
else{ | |
[self flipOff]; | |
} | |
} | |
@end |
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> | |
@interface MBRoundedShadowedView : UIView | |
@property IBInspectable CGFloat cornerRadius; | |
@property IBInspectable CGFloat shadowOpacity; | |
@property IBInspectable (nonatomic) UIColor *shadowColor; | |
@property IBInspectable CGFloat shadowRadius; | |
@property IBInspectable CGSize shadowOffset; | |
@end |
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 "MBRoundedShadowedView.h" | |
@implementation MBRoundedShadowedView | |
- (void)layoutSubviews{ | |
if(_cornerRadius){ | |
self.layer.cornerRadius = self.cornerRadius; | |
self.clipsToBounds = NO; | |
} | |
if(_shadowOpacity){ | |
self.layer.shadowColor = self.shadowColor.CGColor; | |
self.layer.shadowOffset = self.shadowOffset; | |
self.layer.shadowOpacity = self.shadowOpacity; | |
self.layer.shadowRadius = self.shadowRadius; | |
} | |
} | |
@end |
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> | |
@interface MBTypewriterLabel : UILabel | |
@property float typingInterval; | |
@end |
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 "MBTypewriterLabel.h" | |
@implementation MBTypewriterLabel{ | |
NSString *_targetText; | |
int _currentDisplayIndex; | |
NSTimer *_displayTimer; | |
} | |
- (instancetype)initWithCoder:(NSCoder *)aDecoder{ | |
self = [super initWithCoder:aDecoder]; | |
if(self){ | |
self.typingInterval = 0.05; | |
} | |
return self; | |
} | |
- (void)setText:(NSString *)text{ | |
_targetText = text; | |
_currentDisplayIndex = 0; | |
[_displayTimer invalidate]; | |
_displayTimer = [NSTimer scheduledTimerWithTimeInterval:self.typingInterval target:self selector:@selector(onDisplayTimer) userInfo:nil repeats:YES]; | |
} | |
- (NSString *)text{ | |
return _targetText; | |
} | |
- (void)onDisplayTimer{ | |
_currentDisplayIndex++; | |
if(_currentDisplayIndex <= _targetText.length){ | |
NSString *currentText = [_targetText substringToIndex:_currentDisplayIndex]; | |
[super setText: currentText]; | |
} | |
else{ | |
[_displayTimer invalidate]; | |
_displayTimer = nil; | |
} | |
} | |
@end |
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 YUDashedRoundedBorderView : UIView | |
@property (nonatomic) IBInspectable CGFloat borderWidth; | |
@property (nonatomic) IBInspectable CGFloat cornerRadius; | |
@property (nonatomic) IBInspectable UIColor *borderColor; | |
@property (nonatomic) IBInspectable NSInteger dashPattern1; | |
@property (nonatomic) IBInspectable NSInteger dashPattern2; | |
@end |
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 "YUDashedRoundedBorderView.h" | |
@implementation YUDashedRoundedBorderView | |
- (instancetype)initWithCoder:(NSCoder *)aDecoder{ | |
self = [super initWithCoder:aDecoder]; | |
if(self){ | |
} | |
return self; | |
} | |
- (void)drawRect:(CGRect)rect{ | |
[super drawRect:rect]; | |
CGFloat cornerRadius = self.cornerRadius; | |
CGFloat borderWidth = self.borderWidth; | |
NSInteger dashPattern1 = self.dashPattern1; | |
NSInteger dashPattern2 = self.dashPattern2; | |
UIColor *lineColor = self.borderColor; | |
//drawing | |
CGRect frame = self.bounds; | |
CAShapeLayer *_shapeLayer = [CAShapeLayer layer]; | |
//creating a path | |
CGMutablePathRef path = CGPathCreateMutable(); | |
//drawing a border around a view | |
CGPathMoveToPoint(path, NULL, 0, frame.size.height - cornerRadius); | |
CGPathAddLineToPoint(path, NULL, 0, cornerRadius); | |
CGPathAddArc(path, NULL, cornerRadius, cornerRadius, cornerRadius, M_PI, -M_PI_2, NO); | |
CGPathAddLineToPoint(path, NULL, frame.size.width - cornerRadius, 0); | |
CGPathAddArc(path, NULL, frame.size.width - cornerRadius, cornerRadius, cornerRadius, -M_PI_2, 0, NO); | |
CGPathAddLineToPoint(path, NULL, frame.size.width, frame.size.height - cornerRadius); | |
CGPathAddArc(path, NULL, frame.size.width - cornerRadius, frame.size.height - cornerRadius, cornerRadius, 0, M_PI_2, NO); | |
CGPathAddLineToPoint(path, NULL, cornerRadius, frame.size.height); | |
CGPathAddArc(path, NULL, cornerRadius, frame.size.height - cornerRadius, cornerRadius, M_PI_2, M_PI, NO); | |
//path is set as the _shapeLayer object's path | |
_shapeLayer.path = path; | |
CGPathRelease(path); | |
_shapeLayer.backgroundColor = [[UIColor clearColor] CGColor]; | |
_shapeLayer.frame = frame; | |
_shapeLayer.masksToBounds = NO; | |
[_shapeLayer setValue:[NSNumber numberWithBool:NO] forKey:@"isCircle"]; | |
_shapeLayer.fillColor = [[UIColor clearColor] CGColor]; | |
_shapeLayer.strokeColor = [lineColor CGColor]; | |
_shapeLayer.lineWidth = borderWidth; | |
_shapeLayer.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithInteger:dashPattern1], [NSNumber numberWithInteger:dashPattern2], nil]; | |
_shapeLayer.lineCap = kCALineCapSquare; | |
//_shapeLayer is added as a sublayer of the view, the border is visible | |
[self.layer addSublayer:_shapeLayer]; | |
self.layer.cornerRadius = cornerRadius; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment