Skip to content

Instantly share code, notes, and snippets.

@pix0r
Created July 10, 2011 18:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pix0r/1074843 to your computer and use it in GitHub Desktop.
Save pix0r/1074843 to your computer and use it in GitHub Desktop.
CustomTextView (UITextView subclass with border)
//
// CustomTextView.h
//
// Created by Mike Matz on 7/10/11.
// Copyright 2011 Flying Yeti. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface CustomTextView : UITextView {
CGFloat _cornerRadius;
CGFloat _borderWidth;
UIColor *_borderColor;
}
@property (nonatomic, assign) CGFloat cornerRadius;
@property (nonatomic, assign) CGFloat borderWidth;
@property (nonatomic, retain) UIColor *borderColor;
@end
//
// CustomTextView.m
//
// Created by Mike Matz on 7/10/11.
// Copyright 2011 Flying Yeti. All rights reserved.
//
#import "CustomTextView.h"
#import <QuartzCore/QuartzCore.h>
@implementation CustomTextView
@synthesize cornerRadius = _cornerRadius, borderColor = _borderColor, borderWidth = _borderWidth;
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.cornerRadius = 0.0;
self.borderWidth = 0.0;
self.borderColor = nil;
}
return self;
}
- (void)dealloc {
[_borderColor release];
[super dealloc];
}
- (void)layoutSubviews {
CALayer *layer = self.layer;
layer.cornerRadius = self.cornerRadius;
layer.borderWidth = self.borderWidth;
layer.borderColor = self.borderColor.CGColor;
[super layoutSubviews];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment