Skip to content

Instantly share code, notes, and snippets.

@rydermackay
Created October 31, 2012 21:42
Show Gist options
  • Save rydermackay/3990093 to your computer and use it in GitHub Desktop.
Save rydermackay/3990093 to your computer and use it in GitHub Desktop.
//
// 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
//
// 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