Created
October 31, 2012 21:42
-
-
Save rydermackay/3990093 to your computer and use it in GitHub Desktop.
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
// | |
// WPRRoundedLabel.h | |
// Payroll | |
// | |
// Created by Ryder Mackay on 2012-08-28. | |
// Copyright (c) 2012 Endloop Mobile. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
@interface WPRRoundedLabel : UILabel | |
@property (nonatomic, assign) CGFloat cornerRadius; | |
@property (nonatomic, strong) UIColor *borderColor; | |
@property (nonatomic, assign) CGFloat borderWidth; | |
@property (nonatomic, assign) UIEdgeInsets insets; | |
@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
// | |
// WPRRoundedLabel.m | |
// Payroll | |
// | |
// Created by Ryder Mackay on 2012-08-28. | |
// Copyright (c) 2012 Endloop Mobile. All rights reserved. | |
// | |
#import "WPRRoundedLabel.h" | |
#import <QuartzCore/QuartzCore.h> | |
@implementation WPRRoundedLabel | |
static inline CGRect CGRectByApplyingEdgeInsets(CGRect rect, UIEdgeInsets insets) | |
{ | |
rect.origin.x += insets.left; | |
rect.size.width -= (insets.right + insets.left); | |
rect.origin.y += insets.top; | |
rect.size.height -= (insets.bottom + insets.bottom); | |
return rect; | |
} | |
- (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines | |
{ | |
return CGRectByApplyingEdgeInsets([super textRectForBounds:bounds limitedToNumberOfLines:numberOfLines], self.insets);; | |
} | |
- (void)drawTextInRect:(CGRect)rect | |
{ | |
[super drawTextInRect:CGRectByApplyingEdgeInsets(rect, self.insets)]; | |
} | |
- (UIColor *)borderColor | |
{ | |
return [UIColor colorWithCGColor:self.layer.borderColor]; | |
} | |
- (void)setBorderColor:(UIColor *)borderColor | |
{ | |
self.layer.borderColor = borderColor.CGColor; | |
} | |
- (CGFloat)borderWidth | |
{ | |
return self.layer.borderWidth; | |
} | |
- (void)setBorderWidth:(CGFloat)borderWidth | |
{ | |
self.layer.borderWidth = borderWidth; | |
} | |
- (CGFloat)cornerRadius | |
{ | |
return self.layer.cornerRadius; | |
} | |
- (void)setCornerRadius:(CGFloat)cornerRadius | |
{ | |
self.layer.cornerRadius = cornerRadius; | |
} | |
- (void)setInsets:(UIEdgeInsets)insets | |
{ | |
if (UIEdgeInsetsEqualToEdgeInsets(_insets, insets)) { | |
return; | |
} | |
_insets = insets; | |
[self setNeedsDisplay]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment